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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -