adrema/app/Resources/SubactivityResource.php

49 lines
1.1 KiB
PHP
Raw Normal View History

2023-03-07 01:35:39 +01:00
<?php
namespace App\Resources;
use App\Activity;
use App\Activity\Resources\ActivityResource;
use App\Lib\HasMeta;
2023-03-07 09:37:49 +01:00
use App\Subactivity;
2023-03-07 01:35:39 +01:00
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Subactivity
*/
class SubactivityResource extends JsonResource
{
use HasMeta;
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
2023-03-07 09:37:49 +01:00
* @return array<string, mixed>
2023-03-07 01:35:39 +01:00
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'is_filterable' => $this->is_filterable,
'activities' => $this->activities->pluck('id')->toArray(),
'links' => [
'show' => route('api.subactivity.show', ['subactivity' => $this->getModel()]),
'update' => route('api.subactivity.update', ['subactivity' => $this->getModel()]),
],
];
}
2023-03-07 09:37:49 +01:00
/**
* @return array<string, mixed>
*/
2023-03-07 01:35:39 +01:00
public static function meta(): array
{
return [
'activities' => ActivityResource::collectionWithoutMeta(Activity::get()),
];
}
}