Skip to content

Get roles and permissions on /User route #2435

Answered by loxK
loxK asked this question in Q&A
Discussion options

You must be logged in to vote

I found that I can do this, if there is a better way to do it, tell me please:

Route::middleware(['auth:sanctum'])->get('/user', function (Request $request) {

    return [
        'user' => $request->user(),
        'roles' => $request->user()->getRoleNames(),
        'permissions' => $request->user()->getAllPermissions(),
    ];

});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by drbyte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant