Reputation: 9211
I'm using the following query to get all companies for a certain event. And they are ordered by name
$companies = Company::where('city_id', 3)->orderBy('name', 'asc')->get();
Now in my view i use eager loading to get all the persons that work for that company
@foreach($companies as $company)
@foreach($company->persons as $person)
<tr><td>{{ $person->firstname }}</td></tr>
@endforeach
@endforeach
Thanks
Upvotes: 0
Views: 156
Reputation: 1234
You can further query your relations in Laravel.
For example to get person by names in an ascending order.
@foreach($companies as $company)
@foreach($company->persons()->orderBy('firstname','asc')->get() as $person)
<tr><td>{{ $person->firstname }}</td></tr>
@endforeach
@endforeach
Upvotes: 1