31 lines
920 B
PHP
31 lines
920 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class UserResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->public_id,
|
|
'name' => $this->name,
|
|
'username' => $this->username,
|
|
'email' => $this->email,
|
|
'two_factor_enabled' => $this->two_factor_enabled,
|
|
'roles' => $this->getRoleNames(),
|
|
'permissions' => $this->getAllPermissions()->pluck('name'),
|
|
'created_at' => $this->created_at,
|
|
'can_edit' => $request->user()?->can('users.update') ?? false,
|
|
'can_delete' => $request->user()?->can('users.delete') && $request->user()->id !== $this->id,
|
|
];
|
|
}
|
|
}
|