40 lines
1.7 KiB
PHP
40 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use App\Http\Resources\TenantResource;
|
|
use App\Http\Resources\OutletResource;
|
|
|
|
class UserResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'uuid' => $this->uuid,
|
|
'tenant' => new TenantResource($this->whenLoaded('tenant')? : $this->tenant),
|
|
'outlet_id' => $this->outlet->uuid,
|
|
'outlets' => $this->role === 'owner'
|
|
? OutletResource::collection($this->tenant->outlets)
|
|
: new OutletResource($this->outlet),
|
|
'staff_list' => $this->role === 'owner'
|
|
? StaffResource::collection($this->tenant->users->where('uuid', '!=', $this->uuid))
|
|
: [],
|
|
'name' => $this->name,
|
|
'email' => $this->email,
|
|
'phone_number' => $this->phone_number,
|
|
'role' => $this->role,
|
|
'place_of_birth' => $this->place_of_birth,
|
|
'date_of_birth' => $this->date_of_birth,
|
|
'shift_name' => $this->shift_name,
|
|
'shift_start_time' => $this->shift_start_time,
|
|
'shift_end_time' => $this->shift_end_time,
|
|
'is_active' => (bool) $this->is_active,
|
|
'last_sync' => $this->last_sync?->toIso8601String(),
|
|
'created_at' => $this->created_at?->toIso8601String(),
|
|
'updated_at' => $this->updated_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|