> $payload */ public function handle(array $payload): Subactivity { return DB::transaction(function () use ($payload) { $subactivity = Subactivity::create(Arr::except($payload, 'activities')); $subactivity->activities()->sync($payload['activities']); return $subactivity; }); } /** * @return array */ public function rules(): array { return [ 'name' => 'required|unique:subactivities,name', 'activities' => 'present|array|min:1', 'activities.*' => 'integer', 'is_filterable' => 'present|boolean', ]; } /** * @return array */ public function getValidationAttributes(): array { return [ 'activities' => 'Tätigkeiten', ]; } public function asController(ActionRequest $request): JsonResponse { return response()->json($this->handle($request->validated())); } }