2023-12-30 02:02:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Group\Resources;
|
|
|
|
|
2023-12-30 19:02:15 +01:00
|
|
|
use App\Group;
|
2023-12-30 22:21:08 +01:00
|
|
|
use App\Group\Enums\Level;
|
2023-12-30 02:02:07 +01:00
|
|
|
use App\Lib\HasMeta;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
2023-12-30 19:02:15 +01:00
|
|
|
/**
|
|
|
|
* @mixin Group
|
|
|
|
*/
|
2023-12-30 02:02:07 +01:00
|
|
|
class GroupResource extends JsonResource
|
|
|
|
{
|
|
|
|
|
|
|
|
use HasMeta;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2023-12-30 19:02:15 +01:00
|
|
|
* @return array<string, mixed>
|
2023-12-30 02:02:07 +01:00
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
|
|
|
return [
|
2024-04-11 20:03:25 +02:00
|
|
|
'name' => $request->has('prefer_inner') && $this->inner_name ? $this->inner_name : $this->name,
|
2023-12-30 02:02:07 +01:00
|
|
|
'inner_name' => $this->inner_name,
|
|
|
|
'parent_id' => $this->parent_id,
|
|
|
|
'id' => $this->id,
|
|
|
|
'level' => $this->level?->value,
|
2023-12-30 22:21:08 +01:00
|
|
|
'children_count' => $this->children_count,
|
|
|
|
'links' => [
|
|
|
|
'children' => route('api.group', ['group' => $this->id]),
|
|
|
|
]
|
2023-12-30 02:02:07 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-12-30 19:02:15 +01:00
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
2023-12-30 02:02:07 +01:00
|
|
|
public static function meta(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'links' => [
|
|
|
|
'bulkstore' => route('group.bulkstore'),
|
2023-12-30 22:21:08 +01:00
|
|
|
'root_path' => route('api.group'),
|
|
|
|
],
|
|
|
|
'levels' => Level::forSelect(),
|
2023-12-30 02:02:07 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|