adrema/app/Activity/Resources/ActivityResource.php

57 lines
1.5 KiB
PHP
Raw Normal View History

2023-02-14 14:27:11 +01:00
<?php
namespace App\Activity\Resources;
use App\Activity;
2023-02-23 22:43:13 +01:00
use App\Http\Views\ActivityFilterScope;
use App\Lib\HasMeta;
use App\Subactivity;
2023-02-14 14:27:11 +01:00
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Activity
*/
class ActivityResource extends JsonResource
{
2023-02-23 22:43:13 +01:00
use HasMeta;
2023-02-14 14:27:11 +01:00
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
* @return array{id: int, name: string}
*/
public function toArray($request)
{
return [
'name' => $this->name,
'id' => $this->id,
2023-02-25 17:19:17 +01:00
'subactivities' => $this->subactivities->pluck('id')->toArray(),
2023-03-04 12:09:25 +01:00
'is_filterable' => $this->is_filterable,
2023-02-25 17:19:17 +01:00
'links' => [
'edit' => route('activity.edit', ['activity' => $this->getModel()]),
'update' => route('activity.update', ['activity' => $this->getModel()]),
'destroy' => route('activity.destroy', ['activity' => $this->getModel()]),
2023-03-04 12:09:25 +01:00
],
2023-03-04 15:23:45 +01:00
'subactivity_model' => [
'activities' => [$this->id],
'is_age_group' => false,
'is_filterable' => false,
'name' => '',
],
2023-02-14 14:27:11 +01:00
];
}
2023-02-23 22:43:13 +01:00
/**
* @return array<string, mixed>
*/
public static function meta(): array
{
return [
2023-02-25 17:19:17 +01:00
'subactivities' => Subactivity::select('name', 'id')->get(),
2023-02-23 22:43:13 +01:00
'filter' => ActivityFilterScope::fromRequest(request()->input('filter')),
];
}
2023-02-14 14:27:11 +01:00
}