Trying to return all Locations for a User if the user is admin, otherwise use the hasManyThrough function. Curious if this is possible?
public function locations()
{
if ($this->hasRole('Admin')) {
//return all locations
return $this->has(Location::all());
} else {
return $this->hasManyThrough(
Location::class,
UserLocations::class,
'user_id',
'id',
'id',
'location_id'
);
}
}