40 lines
2.1 KiB
PHP
40 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Services\ExistingBusinessClassification;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class PublicBusinessOpportunityResource extends JsonResource
|
|
{
|
|
/** @return array<string, mixed> */
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => data_get($this->resource, 'id'),
|
|
'slug' => data_get($this->resource, 'public_slug'),
|
|
'title' => data_get($this->resource, 'public_title'),
|
|
'modality' => data_get($this->resource, 'modality'),
|
|
'activity_code' => data_get($this->resource, 'activity_code'),
|
|
'stage' => data_get($this->resource, 'stage'),
|
|
'objective' => data_get($this->resource, 'objective'),
|
|
'currency' => data_get($this->resource, 'currency'),
|
|
'amount_min' => data_get($this->resource, 'amount_min'),
|
|
'amount_max' => data_get($this->resource, 'amount_max'),
|
|
'available_percentage' => data_get($this->resource, 'available_percentage'),
|
|
'published_at' => data_get($this->resource, 'published_at'),
|
|
'distance_km' => $this->resource->getAttribute('distance_km') !== null ? round((float) $this->resource->getAttribute('distance_km'), 1) : null,
|
|
'location_recorded_at' => $this->resource->getAttribute('location_recorded_at') ? CarbonImmutable::parse($this->resource->getAttribute('location_recorded_at'))->toIso8601String() : null,
|
|
'location_source_reference' => $this->resource->getAttribute('location_source_reference'),
|
|
'location_source_date' => $this->resource->getAttribute('location_source_date'),
|
|
'sector' => $this->whenLoaded('sector', fn () => data_get($this->resource, 'sector')?->only(['name', 'slug'])),
|
|
'province' => $this->resource->getAttribute('province'),
|
|
'district' => $this->resource->getAttribute('district'),
|
|
'locality' => $this->resource->getAttribute('locality'),
|
|
'multidimensional' => app(ExistingBusinessClassification::class)->publicRows($this->resource),
|
|
];
|
|
}
|
|
}
|