Skip to content

Commit

Permalink
Add roles to user endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TiiFuchs committed Nov 2, 2024
1 parent 053fcd6 commit 16aa542
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function toArray(Request $request): array
'email' => $this->email,
'email_verified_at' => $this->email_verified_at,
'image_url' => $this->image_url,
'roles' => $this->whenLoaded('roles'),
'roles' => $this->whenLoaded('roles', fn () => $this->roles->pluck('name')),
];
}
}
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

Route::get('/user', function (Request $request) {
return new UserResource(
$request->user()
$request->user()->load('roles')
);
})->middleware('auth:api');

0 comments on commit 16aa542

Please sign in to comment.