adrema/app/Activity/Actions/DestroyAction.php

36 lines
899 B
PHP
Raw Normal View History

2023-02-25 17:19:17 +01:00
<?php
namespace App\Activity\Actions;
2023-02-25 19:12:07 +01:00
use App\Activity;
use App\Member\Membership;
use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\ValidationException;
2023-02-25 17:19:17 +01:00
use Lorisleiva\Actions\Concerns\AsAction;
class DestroyAction
{
use AsAction;
2023-02-25 19:12:07 +01:00
public function handle(Activity $activity): void
2023-02-25 17:19:17 +01:00
{
2023-02-25 19:12:07 +01:00
$activity->subactivities()->sync([]);
$activity->delete();
}
public function asController(Activity $activity): RedirectResponse
{
if (Membership::where('activity_id', $activity->id)->count()) {
throw ValidationException::withMessages(['activity' => 'Tätigkeit besitzt noch Mitglieder.']);
}
if ($activity->hasNami) {
throw ValidationException::withMessages(['activity' => 'Tätigkeit ist in NaMi.']);
}
$this->handle($activity);
return redirect()->route('activity.index');
2023-02-25 17:19:17 +01:00
}
}