43 lines
1.7 KiB
PHP
43 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class UserResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->uuid,
|
|
'db_id' => $this->id,
|
|
'full_name' => $this->full_name,
|
|
'email' => $this->email,
|
|
'phone' => $this->phone,
|
|
'first_name' => $this->first_name,
|
|
'middle_name' => $this->middle_name,
|
|
'last_name' => $this->last_name,
|
|
'role' => $this->role,
|
|
'status' => $this->status,
|
|
'preferred_language' => $this->preferred_language,
|
|
'email_verified_at' => $this->email_verified_at?->toIso8601String(),
|
|
'phone_verified_at' => $this->phone_verified_at?->toIso8601String(),
|
|
'last_login_at' => $this->last_login_at?->toIso8601String(),
|
|
'tenant' => $this->relationLoaded('tenant') && $this->tenant ? [
|
|
'id' => $this->tenant->uuid,
|
|
'name' => $this->tenant->name,
|
|
'code' => $this->tenant->code,
|
|
'boundary_polygon' => $this->tenant->boundary_polygon ? (function ($poly) {
|
|
$rings = $poly->getGeometries();
|
|
$ring = $rings->first();
|
|
|
|
return $ring ? $ring->getGeometries()->map(fn ($p) => ['lat' => $p->latitude, 'lng' => $p->longitude])->all() : null;
|
|
})($this->tenant->boundary_polygon) : null,
|
|
] : null,
|
|
'truck' => $this->role === User::ROLE_DRIVER && $this->relationLoaded('driverTeam') && $this->driverTeam?->truck ? new TruckResource($this->driverTeam->truck) : null,
|
|
];
|
|
}
|
|
}
|