I have a method tenants() inside the User model, now inside this method it returns like this below which is working fine,
return $this->belongsToMany(
Municipality::class,
'municipality_user',
'user_id',
'municipality_id'
);
but I want to get all the municipality when the user is a super admin user.
$user->isSuperAdmin()
I tried with this,
if ($this->isSuperAdmin()) {
return Municipality::all();
}
return $this->belongsToMany(
Municipality::class,
'municipality_user',
'user_id',
'municipality_id'
);
but it return this error: App\Models\User::tenants must return a relationship instance.
Should I build a custom belongsToMany class or how can I achieve that?