i have post and post have comments and comments have likes i want to know that is login user like comment or not via Relationship
In controller i return post with comments
return $posts = Post::with('comments')->paginate(3);
In Post Model
public function comments()
{
return $this->hasMany('App\Models\Comment','post_id')
->where('parent_id',0)
->with('user','subComments','like')
->orderBy('id', 'desc');
}
In Comments Model
public function like()
{
return $this->HasMany('App\Models\CommentLike');
}
public function subComments()
{
return $this->hasMany('App\Models\Comment', 'parent_id')->with('user','like');
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/30Qaeak
via IFTTT
Aucun commentaire:
Enregistrer un commentaire