-
app/Enums/Tag/Color.php
Open in GitHubenum Color: string { case RED = 'red'; case ORANGE = 'orange'; case YELLOW = 'yellow'; case GREEN = 'green'; case CYAN = 'cyan'; case TEAL = 'teal'; case BLUE = 'blue'; case INDIGO = 'indigo'; case PURPLE = 'purple'; case FUCHSIA = 'fuchsia'; case PINK = 'pink'; case ZINC = 'zinc'; }
-
app/Models/Tag.php
Open in GitHubuse App\Enums\Tag\Color; class Tag extends Model { // ... protected function casts(): array { return [ 'color' => Color::class, ]; } // ... }
-
app/Http/Requests/Tag/CreateRequest.php
Open in GitHubuse Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rules\Enum; use App\Enums\Tag\Color; class CreateRequest extends FormRequest { public function rules(): array { return [ 'name' => ['required', 'string', 'max:255', 'min:2'], 'color' => ['required','string', 'max:255', new Enum(Color::class)], ]; } }