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 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 17:41:54 +02:00
|
|
|
public function handle(ActionRequest $request, Fileshare $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,
|
|
|
|
]);
|
2024-06-27 18:04:58 +02:00
|
|
|
|
|
|
|
Succeeded::message('Verbindung bearbeitet.')->dispatch();
|
2024-06-27 00:19:12 +02:00
|
|
|
}
|
|
|
|
}
|