adrema/app/Fileshare/Actions/FileshareConnectionStoreAct...

41 lines
954 B
PHP
Raw Normal View History

2024-06-27 00:19:12 +02:00
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\FileshareConnection;
use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
2024-06-27 11:35:10 +02:00
class FileshareConnectionStoreAction
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']);
}
FileshareConnection::create([
...$request->validated(),
'type' => $type,
]);
}
}