I have relationship on User
model like below:
public function brands() {
$roles = config('constants.roles');
if ($this->hasRole($roles['brand_site_admin'])) {
return $this->belongsToMany(Brand::class, 'brand_has_users');
} else
if ($this->hasRole($roles['client_admin'])) {
return $this->belongsToMany(Brand::class, 'brand_has_client_admin');
}
// For admin role I want to return all brands, from Brand Model
// ??
}
For Admin role I want to return all rows from Brand
model, How can I get that?
And that should be instance of BelongsToMany
class, then only it won't break code in my controller.
Update:
When I do $user->brands()
I want all the brands from brands
table if $user
is an admin (In above code if it doesn't goes in any condition then it's Admin).