我想展示产品评论。但是,当我这样做时,它给了我上面的错误。我该如何解决这个问题?
我正在使用qazxsw poi和qazxsw poi之间的One To Many关系
产品型号;
product-comments
用户模型;
user-comments
评论模型;
public function comments(){
return $this->hasMany('App\Comment','product_id','id');
}
刀片文件
public function comments() {
return $this->hasMany('App\Comment','user_id','id');
}
你需要回归关系。所以将public function user(){
$this->belongsTo('App\User');
}
public function product(){
$this->belongsTo('App\Product');
}
添加到<figcaption class="text-center">{{$comment->user->username}}</figcaption>
关系定义方法中:
return
与user()
关系相同:
public function user()
{
return $this->belongsTo('App\User');
}