route()?->parameters()) ->first(fn ($param) => $param instanceof Model); if ($model === null) { throw new \InvalidArgumentException('No model found in route parameters'); } if (! $model instanceof ModelWithStatus || ! $model instanceof Model) { throw new \InvalidArgumentException('Model must implement ModelWithStatus and extend Model'); } $this->authorize('toggleStatus', $model); return DB::transaction(function () use ($model) { $model->toggleStatus(); if ($model->saveOrFail()) { return back()->with('success', trans('crud.messages.has_been_updated', [ 'model' => Str::ucfirst(trans_choice('models.classes.' . $model->getTable(), 1)), ])); } return back()->with('error', trans('crud.messages.cannot_be_updated', [ 'model' => Str::ucfirst(trans_choice('models.classes.' . $model->getTable(), 1)), ])); }); } }