讨论数量:
默认的外键是category_id
吧,你表里是product_category_id
的话,要如下定义关联方法:
public function category()
{
return $this->belongsTo(ProductCategory::class, 'product_category_id');
}
你的结果集中没看到product_category_id
盲猜你的查询语句中没有包含product_category_id
字段,如 select id from table
把id
换成 *
或增加一个product_category_id
推荐文章: