如何解决如何与别名模型建立联系
您好,我有一个名为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);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。