如何使用Laravel Rinvex属性?
我正在尝试使用,但不明白如何使用。 医生对我来说不清楚,我需要帮助 安装软件包后,我将执行以下操作: 我有\App\Models\Product类要创建。 所以我把模型放进去如何使用Laravel Rinvex属性?,laravel,laravel-5,attributes,Laravel,Laravel 5,Attributes,我正在尝试使用,但不明白如何使用。 医生对我来说不清楚,我需要帮助 安装软件包后,我将执行以下操作: 我有\App\Models\Product类要创建。 所以我把模型放进去 use Rinvex\Attributes\Traits\Attributable; class Product extends Model { use CrudTrait; use Sluggable; use Attributable; /***/ 在AppServiceProvider的
use Rinvex\Attributes\Traits\Attributable;
class Product extends Model
{
use CrudTrait;
use Sluggable;
use Attributable;
/***/
在AppServiceProvider的启动()中:
接下来-就像在文档中一样-在Tinker控制台中创建属性,如下所示:
app('rinvex.attributes.attribute')->create([
'slug' => 'size',
'type' => 'varchar',
'name' => 'Product Size',
'entities' => ['App\Models\Product'],
]);
在DB中,我在attributes_条目和attributes表中看到添加的条目
但是当我试着打电话的时候
$product->size = 50;
$product->save(); - got "not found field in Model".
我做错了什么?您是否注册了varchar类型?正如文件中提到的, 默认情况下,Rinvex属性不注册任何类型(请参阅) 因此,我建议您在服务提供商注册方法中添加以下代码:
Attribute::typeMap([
'varchar' => \Rinvex\Attributes\Models\Type\Varchar::class,
]);
别忘了包括这门课
use Rinvex\Attributes\Models\Attribute
use Rinvex\Attributes\Models\Attribute