brokeyourbike/enum-validation

PHP 8.1 enum validation rules for Laravel

0.1.5 2023-08-28 13:35 UTC

This package is auto-updated.

Last update: 2024-10-28 16:14:20 UTC


README

Latest Stable Version Total Downloads Maintainability Test Coverage

PHP 8.1 enum validation rules for Laravel

Installation

composer require brokeyourbike/enum-validation

Usage

use Illuminate\Foundation\Http\FormRequest;
use BrokeYourBike\EnumValidation\IsValidEnum;

enum DrinkEnum: string {
    case WINE = 'wine';
    case VODKA = 'vodka';
}

class ExampleRequest extends FormRequest
{
    public function rules()
    {
        return [
            'drink' => [
                'required',
                'string',
                new IsValidEnum(DrinkEnum::class),
            ],
        ];
    }
}

Authors

License

Mozilla Public License v2.0