【发布时间】:2017-12-29 21:29:49
【问题描述】:
我想展示产品 cmets。但是当我这样做时,它给了我以上错误。我该如何解决?
我正在使用一对多关系 beetwen 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>
【问题讨论】:
标签: php laravel one-to-many laravel-5.5