horat1us/yii2-uuid-validator

Yii2 UUID Validator

1.1.0 2024-11-11 15:01 UTC

This package is auto-updated.

Last update: 2024-12-11 15:08:20 UTC


README

Build Status codecov

Simple validator that uses ramsey/uuid to validate UUID in models etc.

Main purpose of this validator - use it instead of regular expression validator to prevent mistakes.

Installation

Using packagist.org:

composer require horat1us/yii2-uuid-validator:^1.0

Usage

Just add it to rules of our \yii\base\Model:

<?php

namespace App;

use Horat1us\Yii\UuidValidator;
use yii\base;

class Model extends base\Model 
{
    /** @var string attribute to be validated */
    public $uuid;
    
    public function rules() {
        return [
            [['uuid',], 'required',],
            [['uuid',], UuidValidator::class],   
        ];
    }
}

License

MIT