2
商品のコメントを表示したい。しかし、私がそれをすると、それは私の間違いを私に与えます。どうすれば修正できますか?Laravel- 5.5 App Comment :: userはリレーションシップインスタンスを返す必要があります。
私はproduct-comments
とuser-comments
製品モデルbeetwen一対多の関係を使用しています。
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>