*/ public function schema(JsonSchema $schema): array { return [ 'label_id' => $schema->string()->description('Id of the label to edit.')->required(), 'name' => $schema->string()->description('New label name (unique within the space).'), 'color' => $schema->string()->enum(array_column(LabelColor::cases(), 'value'))->description('New label color.'), 'space' => $schema->string()->description('Space id. Defaults to the personal space.'), ]; } protected function write(Request $request, User $user): Response { $request->validate([ 'name' => ['sometimes', 'string', 'max:255'], 'color' => ['sometimes', Rule::enum(LabelColor::class)], ]); $space = $this->resolveSpace($request, $user); $label = $this->labelInSpace($request, $space); if ($request->has('name')) { $name = $request->string('name')->toString(); $exists = Label::query() ->forSpace($space) ->where('name', $name) ->whereKeyNot($label->id) ->exists(); if ($exists) { throw ValidationException::withMessages([ 'name' => 'A label with that name already exists.', ]); } $label->name = $name; } if ($request->has('color')) { $label->color = $request->string('color')->toString(); } $label->save(); return $this->json(['label' => $this->presentLabel($label)]); } }