-
Is it possible to get the user role name in the user model as an accessor? //User Model /**
* Ge the user's role name.
*
* @return Attribute
*/
public function roleName(): Attribute
{
return Attribute::make(
get: function () {
$user = User::find($this->id);
return $user->getRoleNames();
},
);
} |
Beta Was this translation helpful? Give feedback.
Answered by
drbyte
Jul 26, 2024
Replies: 1 comment
-
This package allows more-than-one role to be assigned to a User. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Iairus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This package allows more-than-one role to be assigned to a User.
You would need to add your own custom logic to narrow it down to return just one of the User's roles. Perhaps
->first()
?