adrema/app/Fileshare/Resources/FileshareResource.php

57 lines
1.3 KiB
PHP
Raw Normal View History

2024-06-27 00:00:29 +02:00
<?php
namespace App\Fileshare\Resources;
2024-06-27 11:35:10 +02:00
use App\Fileshare\ConnectionTypes\ConnectionType;
2024-06-27 17:41:54 +02:00
use App\Fileshare\Models\Fileshare;
2024-06-27 11:35:10 +02:00
use App\Lib\HasMeta;
2024-06-27 00:00:29 +02:00
use Illuminate\Http\Resources\Json\JsonResource;
2024-06-27 10:52:45 +02:00
/**
2024-06-29 11:18:40 +02:00
* @mixin Fileshare
2024-06-27 10:52:45 +02:00
*/
2024-06-27 17:41:54 +02:00
class FileshareResource extends JsonResource
2024-06-27 00:00:29 +02:00
{
2024-06-27 11:35:10 +02:00
use HasMeta;
2024-06-27 00:00:29 +02:00
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array<string, mixed>
*/
public function toArray($request)
{
return [
'name' => $this->name,
'is_active' => $this->type->check(),
2024-06-27 00:05:23 +02:00
'type' => get_class($this->type),
'config' => $this->type->toArray(),
'id' => $this->id,
2024-06-27 11:35:10 +02:00
'type_human' => $this->type::title(),
2024-06-27 12:48:20 +02:00
'links' => [
'update' => route('fileshare.update', ['fileshare' => $this->getModel()]),
]
2024-06-27 11:35:10 +02:00
];
}
/**
* @return array<string, mixed>
*/
public static function meta(): array
{
return [
'default' => [
'name' => '',
'type' => null,
'config' => null,
],
'types' => ConnectionType::forSelect(),
'links' => [
'store' => route('fileshare.store'),
]
2024-06-27 00:00:29 +02:00
];
}
}