我正在尝试使用https://github.com/rinvex/attributes,但不明白如何使用。医生对我不清楚,我需要帮助。
在安装完下面完成的软件包之后:
我有\App\Models\Product,我想使其具有可归因性。所以我把模型
use Rinvex\Attributes\Traits\Attributable;
class Product extends Model
{
use CrudTrait;
use Sluggable;
use Attributable;
/***/在AppServiceProvider的boot()中:
app('rinvex.attributes.entities')->push(App\Models\Product::class);接下来--就像在docs中一样--在Tinker控制台中创建属性,如下所示:
app('rinvex.attributes.attribute')->create([
'slug' => 'size',
'type' => 'varchar',
'name' => 'Product Size',
'entities' => ['App\Models\Product'],
]);在DB中,我看到在attributes_entries和属性表中添加了条目。
但当我试着打电话
$product->size = 50;
$product->save(); - got "not found field in Model".我做错什么了?
发布于 2018-11-06 11:44:11
你注册varchar类型了吗?正如文档中所提到的,Rinvex属性在默认情况下不注册任何类型的(参见https://github.com/rinvex/laravel-attributes#register-your-types)。
因此,我建议您在服务提供商注册方法中添加此代码:
Attribute::typeMap([
'varchar' => \Rinvex\Attributes\Models\Type\Varchar::class,
]);别忘了包括这门课
use Rinvex\Attributes\Models\Attributehttps://stackoverflow.com/questions/52465091
复制相似问题