adrema/app/Activity/Actions/ActivityStoreAction.php

45 lines
952 B
PHP
Raw Normal View History

2023-02-15 01:36:59 +01:00
<?php
namespace App\Activity\Actions;
use App\Activity;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class ActivityStoreAction
{
use AsAction;
/**
* @param array<string, mixed> $payload
*/
public function handle(array $payload): Activity
{
$activity = Activity::create($payload);
$activity->subactivities()->sync($payload['subactivities']);
return $activity;
}
/**
* @return array<string, string>
*/
public function rules(): array
{
return [
'name' => 'required|max:255',
2023-03-04 12:09:25 +01:00
'is_filterable' => 'present|boolean',
2023-02-15 01:36:59 +01:00
'subactivities' => 'present|array',
];
}
public function asController(ActionRequest $request): RedirectResponse
{
$this->handle($request->validated());
2023-02-25 18:00:23 +01:00
return redirect()->route('activity.index');
2023-02-15 01:36:59 +01:00
}
}