2024-01-12 22:52:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Resources;
|
|
|
|
|
|
|
|
use App\Form\Models\Form;
|
|
|
|
use App\Lib\HasMeta;
|
2024-02-23 01:08:13 +01:00
|
|
|
use App\Subactivity;
|
2024-01-12 22:52:42 +01:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin Form
|
|
|
|
*/
|
|
|
|
class FormApiResource extends JsonResource
|
|
|
|
{
|
|
|
|
use HasMeta;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
|
|
|
'name' => $this->name,
|
|
|
|
'from_human' => $this->from->format('d.m.Y'),
|
|
|
|
'to_human' => $this->to->format('d.m.Y'),
|
|
|
|
'excerpt' => $this->excerpt,
|
|
|
|
'description' => $this->description,
|
|
|
|
'config' => $this->config,
|
|
|
|
'slug' => $this->slug,
|
|
|
|
'dates' => $this->from->equalTo($this->to) ? $this->from->format('d.m.Y') : $this->from->format('d.m.Y') . ' - ' . $this->to->format('d.m.Y'),
|
2024-01-19 18:16:57 +01:00
|
|
|
'image' => $this->getMedia('headerImage')->first()->getFullUrl('square'),
|
2024-01-12 22:52:42 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public static function meta(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'base_url' => url(''),
|
2024-02-23 01:08:13 +01:00
|
|
|
'agegroups' => Subactivity::remote()->where('is_age_group', true)->get()
|
|
|
|
->map(fn ($subactivity) => ['id' => $subactivity->nami_id, 'name' => $subactivity->name]),
|
2024-01-12 22:52:42 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|