Scenario:
An alert belongs to 1 user and 1 location, both referenced, respectively, by foreign keys in the alert table - user_id and location_id. The user_id will be the same for each request, but the location_id most definitely differs.
I want to display all alerts relating to that one user, I have successfully achieved this but without the use of eager loading.
my getIndex function so far:
public function getIndex()
{
$alert = User::with('alerts.location')
->where('id', '=', Auth::user()->id)->first();
$this->layout->content = View::make('agents.index',
array('alert' => $alert));
}
Printing the MYSQL query seems logically correct however, I am struggling to show the 'locations' part of the query.
My foreach loop is:
@foreach($alert->locations as $alert)
<td>{{ $alert->location->address_1}}</td>
@endforeach
However, it returns the error:
Invalid argument supplied for foreach()
Thank you for your help.