47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources\Api\V1;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
final class PersonResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'event_id' => $this->event_id,
|
|
'name' => $this->name,
|
|
'email' => $this->email,
|
|
'phone' => $this->phone,
|
|
'status' => $this->status,
|
|
'is_blacklisted' => $this->is_blacklisted,
|
|
'admin_notes' => $this->admin_notes,
|
|
'custom_fields' => $this->custom_fields,
|
|
'created_at' => $this->created_at->toIso8601String(),
|
|
'crowd_type' => new CrowdTypeResource($this->whenLoaded('crowdType')),
|
|
'company' => new CompanyResource($this->whenLoaded('company')),
|
|
'tags' => $this->when(
|
|
$this->user_id && $this->relationLoaded('user'),
|
|
function () {
|
|
$orgId = $this->event?->organisation_id;
|
|
if (!$orgId || !$this->user) {
|
|
return [];
|
|
}
|
|
|
|
return UserOrganisationTagResource::collection(
|
|
$this->user->organisationTags()
|
|
->where('organisation_id', $orgId)
|
|
->with('personTag')
|
|
->get()
|
|
);
|
|
},
|
|
[]
|
|
),
|
|
];
|
|
}
|
|
}
|