adrema/app/Fileshare/Actions/FileshareUpdateAction.php

40 lines
961 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 12:48:20 +02:00
class FileshareUpdateAction
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 12:48:20 +02:00
public function handle(ActionRequest $request, FileshareConnection $fileshare): 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 12:48:20 +02:00
$fileshare->update([
2024-06-27 00:19:12 +02:00
...$request->validated(),
'type' => $type,
]);
}
}