scybulski/laravel-validator-color
Validate colors with Laravel 5+
This package will let you validate that a certain value is a valid CSS color string.
Installation
Install via composer - In the terminal:
composer require scybulski/laravel-validator-color
Usage
You can use this package either by passing strings to Validator or using Rule Objects.
Validator strings
You need to register a service provider by adding the following to the providers array in your config/app.php
scybulski\Validator\Color\ServiceProvider::class
Then you can use the rules in a Controller or Form Request as following.
use Illuminate\Foundation\Http\FormRequest;
class MyClass extends FormRequest
{
public function rules()
{
return [
'color' => 'required|other_rule|color',
'color_hex' => 'required|other_rule|color_hex',
'color_keyword' => 'required|other_rule|color_keyword',
'color_long_hex' => 'required|other_rule|color_long_hex',
'color_rgb' => 'required|other_rule|color_rgb',
'color_rgba' => 'required|other_rule|color_rgba',
'color_rgb_any' => 'required|other_rule|color_rgb_any',
'color_short_hex' => 'required|other_rule|color_short_hex',
];
}
}
Rule Objects
You can define validation rules in a Controller or Form Request as following.
use Illuminate\Foundation\Http\FormRequest;
use scybulski\Validator\Color\Rules\Color;
use scybulski\Validator\Color\Rules\ColorHex;
use scybulski\Validator\Color\Rules\ColorKeyword;
use scybulski\Validator\Color\Rules\ColorLongHex;
use scybulski\Validator\Color\Rules\ColorRgb;
use scybulski\Validator\Color\Rules\ColorRgba;
use scybulski\Validator\Color\Rules\ColorRgbAny;
use scybulski\Validator\Color\Rules\ColorShortHex;
class MyClass extends FormRequest
{
public function rules()
{
return [
'color' => ['required', 'other_rule', new Color],
'color_hex' => ['required', 'other_rule', new ColorHex],
'color_keyword' => ['required', 'other_rule', new ColorKeyword],
'color_long_hex' => ['required', 'other_rule', new ColorLongHex],
'color_rgb' => ['required', 'other_rule', new ColorRgb],
'color_rgba' => ['required', 'other_rule', new ColorRgba],
'color_rgb_any' => ['required', 'other_rule', new ColorRgbAny],
'color_short_hex' => ['required', 'other_rule', new ColorShortHex],
];
}
}
Related Packages
tylercd100/laravel-validator-color
Validate that a certain value is a valid CSS color string in Laravel 5
81,613
15
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 4.4.2 | >=7.4 <8.4 | >=6.0 <11.0 | MIT | |
| 4.4.1 | >=7.4 <8.3 | >=6.0 <11.0 | MIT | |
| 4.4.0 | >=7.4 <8.3 | >=6.0 <10.0 | MIT | |
| 4.3.0 | >=7.4 <8.2 | >=6.0 <10.0 | MIT | |
| 4.2.0 | >=7.0 <8.1 | >=5.0 <9.0 | MIT | |
| 4.1.0 | >=7.0 <7.5 | >=5.0 <8.0 | MIT | |
| 4.0.0 | >=7.0 <7.5 | >=5.0 <7.0 | MIT | |
| 3.0.2 | ^5.5.9| | ^5.0 | MIT | |
| 3.0.1 | ^5.5.9| | ^5.0 | MIT | |
| 3.0.0 | ^5.5.9| | ^5.0 | MIT | |
| 2.0.0 | ^5.5.9| | ^5.0 | MIT | |
| 1.0.0 | ^5.5.9| | ^5.0 | MIT |