This package will let you validate that a certain value is a valid CSS color string using Laravel >= 10.
- PHP 8.1
- Laravel 10
Install via composer - In the terminal:
composer require kaishiyoku/laravel-color-validation
If you're not using package auto-discovery add the following to the providers
array in your config/app.php
Kaishiyoku\Validation\Color\ServiceProvider::class,
// Test any color type
Validator::make(['test' => '#454ACF'], ['test' => 'color']);
// Test for rgb
Validator::make(['test' => 'rgb(0, 200, 150)'], ['test' => 'color_rgb']);
// Test for rgba
Validator::make(['test' => 'rgba(0, 200, 150, 0.52)'], ['test' => 'color_rgba']);
// Test for hex
Validator::make(['test' => '#333'], ['test' => 'color_hex']);
// Test for color name
Validator::make(['test' => 'DeepSkyBlue'], ['test' => 'color_name']);
Validator::make(['test' => 'transparent'], ['test' => 'color_name']);
By default English, German and French locales can be used. If you're using a different locale you will have to add a validation.php
file and a custom folder named after the locale code (e.g. ja
for Japanese) to the /resources/lang/vendor/color_validation/
folder.
Example folder structure:
.
└── resources
└── lang
└── vendor
└── color_validation
├── de
├── en
└── ja
If you want to change any of the existing translations, you can publish the locale files with:
php artisan vendor:publish --provider="Kaishiyoku\Validation\Color\ServiceProvider"
MIT (https://github.com/Kaishiyoku/laravel-color-validation/blob/master/LICENSE)
Website: andreas-wiedel.de