laravel - Is it possible to put multiple relation constraints in a single method in Eloquent? -
i have query looks this:
post::wherehas('comments', function ($query) { $query->where('content', 'like', 'foo%'); })->wherehas('comments', function ($query) { $query->where('content', 'like', 'bar%'); })->get() like need posts, have 1 comment text 'foo' , 1 comment text 'bar'. can somehow mix 2 requests in single one?
yes, it's possible chain multiple clauses can use :: once (after model name), others should -> how added ->get().
so end with:
post::wherehas('comments', function ($query) { $query->where('content', 'like', 'foo%'); })->wherehas('comments', function ($query) { $query->where('content', 'like', 'bar%'); })->get()
Comments
Post a Comment