0

Query:

$professions = Profession::whereHas("users", function($q) use($query) {
    $q->where("professions.name", "like", "%".$query."%");
})->withCount('users')->with(['users' => function($q) {
    $q->take(2);
}])->paginate(10);

When I launched this code, I thought that as a result I would get 2 users for each profession. But as a result, I got 2 users only for the first profession by array key. But I wanted to get 2 users for each profession. How can I make my idea work or is it impossible?

Andreas Hunter
  • 4,504
  • 11
  • 65
  • 125

0 Answers0