51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\Talk;
|
|
use App\Support\TranslatablePayload;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* @mixin Talk
|
|
*/
|
|
class TalkResource extends JsonResource
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$locale = $request->query(config('locales.query_parameter')) ?? app()->getLocale();
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'locale' => $locale,
|
|
'title' => $this->title,
|
|
'language' => $this->language,
|
|
|
|
...TranslatablePayload::resolve($this->resource, $this->translatable, $locale),
|
|
|
|
'event' => $this->event,
|
|
'city' => $this->city,
|
|
'held_at' => $this->held_at?->toDateString(),
|
|
'video_url' => $this->video_url,
|
|
'slides_url' => $this->slides_url,
|
|
'member_id' => $this->member_id,
|
|
'project_id' => $this->project_id,
|
|
'is_public' => (bool) $this->is_public,
|
|
|
|
'created_at' => $this->created_at?->toIso8601String(),
|
|
'updated_at' => $this->updated_at?->toIso8601String(),
|
|
|
|
'translations' => $this->when(
|
|
in_array('translations', explode(',', (string) $request->query('with')), true),
|
|
fn () => TranslatablePayload::all($this->resource, $this->translatable),
|
|
),
|
|
];
|
|
}
|
|
}
|