kaishiyoku/laravel-color-validation

Laravel color validation rules

3.1.0 2024-03-11 22:14 UTC

This package is auto-updated.

Last update: 2024-10-11 23:18:20 UTC


README

Tests Latest Stable Version Total Downloads License PHP Version Require

About

This package will let you validate that a certain value is a valid CSS color string using Laravel >= 10.

Minimum requirements

  • PHP 8.1
  • Laravel 10

Installation

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,

Usage

// 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']);

Using other locales

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

Adjusting existing locales

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"

License

MIT (https://github.com/Kaishiyoku/laravel-color-validation/blob/master/LICENSE)

Author

Website: andreas-wiedel.de