horat1us/yii2-uuid-validator

Yii2 UUID Validator

1.0.1 2019-03-19 04:31 UTC

This package is auto-updated.

Last update: 2024-10-19 16:59:33 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