Laravel ORM带过滤器

Here are my tables in DB:

posts: id,group,creator,body,hide

like_user_post_relationships: id,user,post

Model:LikeUserPostRelationship:

user belongsTo(User::class,'user')

post belongsTo(Post::class,'post')

How do I query all LikeUserPostRelationship::Where('user','=',$user->id)->with('post')->get(); And filter out the LikeUserPostRelationship collection with $post->hide = true?

appreciate any help!

You could use whereDoesntHave() for your criteria which will filter out the results where related post is set as hide = true

$results = LikeUserPostRelationship::with('post')
                        ->where('user','=',$user->id)
                        ->whereDoesntHave('post', function ($query) {
                            $query->where('hide', '=', true);
                        })
                        ->get();

See Querying Relationship Absence