问题描述
您好,我有一个名为Product
的模型和两个名为ProductImage
和ProductAttribute
的模型
我希望什么? 我想访问产品属性并使用以下内容获取它们:
Product:with(['attribute','image','category']);
如果我将访问laravel属性,则返回此错误
Syntax error or access violation: 1066 Not unique table/alias: 'product_attributes'
在我的
Product
模型中
class Product extends Model
{
protected $fillable = [
'name','description','category_id',];
protected $guarded = [
'id',];
protected $dates = [
'created_at','updated_at',];
public function category()
{
return $this->belongsTo(Category::class);
}
public function attribute()
{
return $this->belongsToMany(ProductAttributes::class,'product_attributes');
}
}
在我的
ProductAttribute
模型中
class ProductAttributes extends Model
{
protected $fillable = [
'attribute','value','price','product_id','stock'
];
public function product()
{
return $this->belongsTo(Product::class);
}
}
评论:我正在使用laravel作为REST API
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)