2023-06-13 22:03:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Maildispatcher\Resources;
|
|
|
|
|
|
|
|
use App\Lib\HasMeta;
|
2023-06-15 00:33:13 +02:00
|
|
|
use App\Maildispatcher\Models\Maildispatcher;
|
2024-10-24 23:17:23 +02:00
|
|
|
use Modules\Mailgateway\Models\Mailgateway;
|
2023-06-13 22:03:32 +02:00
|
|
|
use App\Mailgateway\Resources\MailgatewayResource;
|
|
|
|
use App\Member\FilterScope;
|
2023-06-14 17:29:22 +02:00
|
|
|
use App\Member\Member;
|
2023-06-13 22:03:32 +02:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
2023-06-15 00:33:13 +02:00
|
|
|
/**
|
|
|
|
* @mixin Maildispatcher
|
|
|
|
*/
|
2023-06-13 22:03:32 +02:00
|
|
|
class MaildispatcherResource extends JsonResource
|
|
|
|
{
|
|
|
|
use HasMeta;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
2023-06-15 00:33:13 +02:00
|
|
|
* @return array<string, mixed>
|
2023-06-13 22:03:32 +02:00
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'name' => $this->name,
|
|
|
|
'gateway' => new MailgatewayResource($this->whenLoaded('gateway')),
|
2023-06-15 00:08:01 +02:00
|
|
|
'gateway_id' => $this->gateway_id,
|
|
|
|
'filter' => $this->filter,
|
|
|
|
'id' => $this->id,
|
|
|
|
'links' => [
|
|
|
|
'edit' => route('maildispatcher.edit', ['maildispatcher' => $this->getModel()]),
|
|
|
|
'update' => route('maildispatcher.update', ['maildispatcher' => $this->getModel()]),
|
|
|
|
'delete' => route('maildispatcher.destroy', ['maildispatcher' => $this->getModel()]),
|
|
|
|
],
|
2023-06-13 22:03:32 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public static function meta(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'links' => [
|
|
|
|
'create' => route('maildispatcher.create'),
|
|
|
|
'index' => route('maildispatcher.index'),
|
|
|
|
],
|
|
|
|
'default_model' => [
|
|
|
|
'name' => '',
|
|
|
|
'gateway_id' => null,
|
|
|
|
'filter' => FilterScope::from([])->toArray(),
|
|
|
|
],
|
2023-06-14 17:29:22 +02:00
|
|
|
'members' => Member::ordered()->get()->map(fn ($member) => ['id' => $member->id, 'name' => $member->fullname]),
|
|
|
|
'gateways' => Mailgateway::pluck('name', 'id'),
|
2023-06-13 22:03:32 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|