mirror of
https://github.com/koel/koel
synced 2024-12-21 01:53:11 +00:00
28 lines
754 B
PHP
28 lines
754 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class UserResource extends JsonResource
|
|
{
|
|
public function __construct(private User $user, private bool $includePreferences = false)
|
|
{
|
|
parent::__construct($user);
|
|
}
|
|
|
|
/** @return array<mixed> */
|
|
public function toArray($request): array
|
|
{
|
|
return [
|
|
'type' => 'users',
|
|
'id' => $this->user->id,
|
|
'name' => $this->user->name,
|
|
'email' => $this->user->email,
|
|
'avatar' => $this->user->avatar,
|
|
'is_admin' => $this->user->is_admin,
|
|
'preferences' => $this->when($this->includePreferences, $this->user->preferences),
|
|
];
|
|
}
|
|
}
|