2024-06-27 16:58:11 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources\Api\V0;
|
|
|
|
|
2024-08-08 16:11:50 -04:00
|
|
|
use App\Http\Controllers\Api\V0\ApiController;
|
2024-06-27 16:58:11 -04:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
/** @mixin User */
|
|
|
|
class UserResource extends JsonResource
|
|
|
|
{
|
2024-09-12 13:19:52 -04:00
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*/
|
2024-06-27 16:58:11 -04:00
|
|
|
public function toArray(Request $request): array
|
|
|
|
{
|
2024-10-12 13:19:54 -06:00
|
|
|
$this->load('role');
|
|
|
|
|
2024-06-27 16:58:11 -04:00
|
|
|
return [
|
|
|
|
'type' => 'user',
|
|
|
|
'id' => $this->id,
|
|
|
|
'attributes' => [
|
|
|
|
'name' => $this->name,
|
|
|
|
'user_role_id' => $this->user_role_id,
|
|
|
|
'created_at' => $this->created_at,
|
2024-08-08 16:11:50 -04:00
|
|
|
'updated_at' => $this->updated_at,
|
2024-06-27 16:58:11 -04:00
|
|
|
],
|
|
|
|
'relationships' => [
|
|
|
|
'user_role' => [
|
|
|
|
'data' => [
|
|
|
|
'type' => 'user_role',
|
|
|
|
'id' => $this->user_role_id,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2024-08-08 16:11:50 -04:00
|
|
|
'includes' => $this->when(
|
|
|
|
ApiController::shouldInclude('user_role'),
|
2024-10-12 13:20:40 -06:00
|
|
|
new UserRoleResource($this->role),
|
2024-08-08 16:11:50 -04:00
|
|
|
),
|
2024-08-07 23:30:09 -04:00
|
|
|
'links' => [
|
|
|
|
'self' => $this->profileUrl(),
|
|
|
|
],
|
2024-06-27 16:58:11 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|