samedi 29 juillet 2017

Query with two laravel models and return result

I have two models, User and Post

Relationship: post belongsTo user and user hasMany post

In my controller I have a public function which has:

$users = User::orderBy('is_ban', 'desc')->paginate(10);
$posts = Post::orderBy('created_at', 'desc')->paginate(10);

Which is working as expected. I also have one column in users table `is_ban' It's of boolean type.

I am looking for a query which will return the following:

Only get post which has been made by the user which has is_ban=false



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire