diff --git a/app/Activity/Api/SubactivityUpdateAction.php b/app/Activity/Api/SubactivityUpdateAction.php index 15e63030..161bc09f 100644 --- a/app/Activity/Api/SubactivityUpdateAction.php +++ b/app/Activity/Api/SubactivityUpdateAction.php @@ -38,8 +38,11 @@ class SubactivityUpdateAction */ public function rules(): array { + /** @var Subactivity */ + $subactivity = request()->route('subactivity'); + return [ - 'name' => ['required', 'string', 'max:255', Rule::unique('subactivities', 'name')->ignore(request()->route('subactivity')->id)], + 'name' => ['required', 'string', 'max:255', Rule::unique('subactivities', 'name')->ignore($subactivity->id)], 'activities' => ['present', 'array', 'min:1'], 'activities.*' => 'integer', 'is_filterable' => 'present|boolean', @@ -64,7 +67,7 @@ class SubactivityUpdateAction $removingActivities = $subactivity->activities()->whereNotIn('id', $request->validated('activities'))->pluck('id'); - if ($removingActivities->first(fn ($activity) => Membership::firstWhere(['activity_id' => $activity, 'subactivity_id' => $subactivity->id]))) { + if ($removingActivities->first(fn ($activity) => Membership::where(['activity_id' => $activity, 'subactivity_id' => $subactivity->id])->exists())) { throw ValidationException::withMessages(['activities' => 'Tätigkeit hat noch Mitglieder.']); } @@ -74,7 +77,7 @@ class SubactivityUpdateAction /** * @todo handle this with a model event on the pivot model * - * @param Payload $payload + * @param array{name: string, activities: array<int, int>} $payload */ private function validateNami(Subactivity $subactivity, array $payload): void { diff --git a/app/Lib/HasMeta.php b/app/Lib/HasMeta.php index 854e8899..9fbdf14d 100644 --- a/app/Lib/HasMeta.php +++ b/app/Lib/HasMeta.php @@ -25,6 +25,13 @@ trait HasMeta ]); } + /** + * Create a new anonymous resource collection without meta. + * + * @param mixed $resource + * + * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection + */ public static function collectionWithoutMeta($resource) { return parent::collection($resource); diff --git a/app/Resources/SubactivityResource.php b/app/Resources/SubactivityResource.php index aa6100eb..f88ebb0c 100644 --- a/app/Resources/SubactivityResource.php +++ b/app/Resources/SubactivityResource.php @@ -5,6 +5,7 @@ namespace App\Resources; use App\Activity; use App\Activity\Resources\ActivityResource; use App\Lib\HasMeta; +use App\Subactivity; use Illuminate\Http\Resources\Json\JsonResource; /** @@ -19,7 +20,7 @@ class SubactivityResource extends JsonResource * * @param \Illuminate\Http\Request $request * - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @return array<string, mixed> */ public function toArray($request) { @@ -35,6 +36,9 @@ class SubactivityResource extends JsonResource ]; } + /** + * @return array<string, mixed> + */ public static function meta(): array { return [