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