Fetch All users who has at least one post in laravel
laravel, laravel-5
Solution
Try `has()` method for Eloquent models -> https://laravel.com/docs/5.4/eloquent-relationships
$users = User::with('post')->has('post')->get();
You can take users with active posts using `whereHas()`. Remember it. :)
$users = User::with('post')->whereHas('post', function ($query) {
$query->where('is_active', '=', true);
})->get();
Problem
Please guide me, How can I get all users in Laravel, who has posted at least single post. And skip who has not posted any posts. I am trying this. But it is getting All users. ``` $users = User::with('post')->get(); ```