Scopes can receive parameters, so you can pass the role and use it to dynamize a single scope:
public function scopeUserRole($query, $user)
{
switch ($user->role) {
case 'super_manager':
break;
case 'manager':
$query->where ('team_id', $user->team_id);
break;
default:
$query->where ('user_id', $user->id);
}
return $query;
}
Obvoiusly this is a simplycistic case that you have to adapt to your situation, e.g. if the role is managed by gates and the scope is refrred to current logged in user, you can omit the $user parameter and do something like this:
$user = auth()->user();
if ($user->can('manager')
$query->where ('team_id', $user->team_id);