As I stated in the comment as may be seen in your previous questions: You must learn what is returned from the queries (Collection of models or Model) and how dynamic properties (loading relations) works. To make it perfectly clear for you, a little guidance first:
// Company model
public function users()
{
return $this->belongsToMany('User')->withTimestamps();
}
// now you can do this:
$company = Company::find($someId);
$company->users;
// which does behind the scenes:
$company->users()->get();
// thus returned Collection
// Alert model
public function location()
{
return $this->hasOne('Location');
}
// calling relation:
$alert = Alert::find($id);
$alert->location; // single model because it does the same as:
$alert->location()->first();
That being said, you may access related models like this:
$company->users->first()->alerts->first()->location->address_1;
// and for your needs use of course loops:
// don't call it $alerts as it returns company with some relations
$company = Company::with('users.alerts.location')
->where('id', '=', $company_id)
->first(); // use first not get for the reason I mentioned above
@foreach ($company->users as $user)
@foreach ($user->alerts as $alert)
{{ $alert->location->address_1 }}
...
@endforeach
@endforeach
Trashed alerts:
// User model
// additional relation for ease of use
public function deletedAlerts()
{
return $this->hasMany('Alert')->onlyTrashed();
}
// only change in the call is replacing alerts with deletedAlerts:
$company = Company::with('users.deletedAlerts.location')
->where('id', '=', $company_id)
->first();
@foreach ($company->users as $user)
@foreach ($user->deletedAlerts as $alert)
{{ $alert->location->address_1 }}
...
@endforeach
@endforeach