Use DISTINCT in Laravel's withCount() method – Phpmyadmin
With Laravel/Lumen eloquent I can get count relations like this: User::withCount('views')->get(); this will use SQL select `users`.*, (select count(*) from `views` where `users`.`id` = `views`.`user_id`) as `views_count` from `users` and return all models with views_count attribute, great. But I need…