I have a staff table with a field district_id. I need a request that selects the first employee from each district.
Currently, I manually hardcode it:
$tributes = [
Employee::where('district_id', '=' 1)->take(1)->get(),
Employee::where('district_id', '=' 2)->take(1)->get(),
Employee::where('district_id', '=' 3)->take(1)->get(),
...
];
Can this be done using only one eloquent call? Any volunteers?
source
share