diff --git a/app/Activity/Actions/DestroyAction.php b/app/Activity/Actions/DestroyAction.php index f5c7f7de..e02306fe 100644 --- a/app/Activity/Actions/DestroyAction.php +++ b/app/Activity/Actions/DestroyAction.php @@ -2,14 +2,34 @@ namespace App\Activity\Actions; +use App\Activity; +use App\Member\Membership; +use Illuminate\Http\RedirectResponse; +use Illuminate\Validation\ValidationException; use Lorisleiva\Actions\Concerns\AsAction; class DestroyAction { use AsAction; - public function handle() + public function handle(Activity $activity): void { - // ... + $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'); } } diff --git a/resources/js/views/activity/VIndex.vue b/resources/js/views/activity/VIndex.vue index aa2678a2..f36b51a0 100644 --- a/resources/js/views/activity/VIndex.vue +++ b/resources/js/views/activity/VIndex.vue @@ -1,5 +1,16 @@