adrema/app/Setting/Actions/StoreAction.php

45 lines
1.0 KiB
PHP
Raw Normal View History

2024-08-01 13:33:28 +02:00
<?php
namespace App\Setting\Actions;
2024-08-01 17:30:55 +02:00
use App\Lib\Events\Succeeded;
2024-08-01 13:33:28 +02:00
use App\Setting\Contracts\Storeable;
2024-08-01 17:30:55 +02:00
use GrahamCampbell\ResultType\Success;
2024-08-01 13:33:28 +02:00
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class StoreAction
{
use AsAction;
/**
* @param array<string, mixed> $input
*/
public function handle(Storeable $settings, array $input): void
{
$settings->fill($input)->save();
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
/** @var Storeable */
$group = request()->route('settingGroup');
return $group->rules();
}
public function asController(ActionRequest $request, Storeable $settingGroup): RedirectResponse
{
$settingGroup->beforeSave($request);
2024-08-01 17:30:55 +02:00
$this->handle($settingGroup, $settingGroup->saveAttributes($request));
Succeeded::message('Einstellungen gespeichert')->dispatch();
2024-08-01 13:33:28 +02:00
return redirect()->back();
}
}