adrema/app/Fileshare/Actions/FileshareStoreAction.php

43 lines
1018 B
PHP
Raw Normal View History

2024-06-27 00:19:12 +02:00
<?php
namespace App\Fileshare\Actions;
2024-06-27 17:41:54 +02:00
use App\Fileshare\Models\Fileshare;
2024-06-27 18:04:58 +02:00
use App\Lib\Events\Succeeded;
2024-06-27 00:19:12 +02:00
use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
2024-06-27 12:48:20 +02:00
class FileshareStoreAction
2024-06-27 00:19:12 +02:00
{
use AsAction;
2024-06-27 10:52:45 +02:00
/**
* @return array<string, mixed>
*/
2024-06-27 00:19:12 +02:00
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'type' => 'required|string|max:255|exclude',
'config' => 'array|exclude',
];
}
2024-06-27 10:52:45 +02:00
public function asController(ActionRequest $request): void
2024-06-27 00:19:12 +02:00
{
$type = $request->input('type')::from($request->input('config'));
if (!$type->check()) {
throw ValidationException::withMessages(['type' => 'Verbindung fehlgeschlagen']);
}
2024-06-27 17:41:54 +02:00
Fileshare::create([
2024-06-27 00:19:12 +02:00
...$request->validated(),
'type' => $type,
]);
2024-06-27 18:04:58 +02:00
Succeeded::message('Verbindung erstellt.')->dispatch();
2024-06-27 00:19:12 +02:00
}
}