samedi 31 août 2019

How to get is user like comment or not via Laravel Relationship?

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');
    }




via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire