2022-06-10 10:47:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
class UserResource extends JsonResource
|
|
|
|
{
|
2022-08-08 16:00:59 +00:00
|
|
|
public function __construct(private User $user, private bool $includePreferences = false)
|
2022-06-10 10:47:46 +00:00
|
|
|
{
|
|
|
|
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,
|
2022-08-08 16:00:59 +00:00
|
|
|
'preferences' => $this->when($this->includePreferences, $this->user->preferences),
|
2022-06-10 10:47:46 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|