laravel - Query a relationship with where - let result affect parent? -


i query relationship:

return user::with(array('product' => function($q){         $q->where('published', 1);     }))->get(); 

if product not published, relationship null.

if product not published, want not return user.

for example, query should users have published product. if user not have published product, not return them.

is possible? or have checking on view , not output user if product null?

so if understand correctly want return users have product published?

if you're looking wherehas() function, allows return results of parent model based on parameters of relation.

return user::wherehas('product', function($query) {     $query->where('published', true); })->get(); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -