Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

luadotsh/lua

324 stars
3 code files
View luadotsh/lua on GitHub

app/Enums/Tag/Color.php

Open in GitHub
enum 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 GitHub
use App\Enums\Tag\Color;
 
class Tag extends Model
{
// ...
 
protected function casts(): array
{
return [
'color' => Color::class,
];
}
 
// ...
}

app/Http/Requests/Tag/CreateRequest.php

Open in GitHub
use 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)],
];
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.