horat1us / yii2-uuid-behavior
Yii2 UUID generation behavior
Installs: 4 062
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=7.2
- ramsey/uuid: ^3.8
- yiisoft/yii2: ^2.0.15
Requires (Dev)
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-11-05 05:50:37 UTC
README
Behavior to generate UUID values (mostly, for ActiveRecord primary key).
Installation
Using packagist.org:
composer require horat1us/yii2-uuid-behavior:^1.0
Usage
To generate UUID for primary key follow example:
<?php namespace App; use Horat1us\Yii\UuidBehavior; use yii\db; /** * Class Record * @package App * * @property string $uuid // primary key in database, without default value and auto-increment */ class Record extends db\ActiveRecord { public function behaviors(): array { return [ 'uuid' => [ 'class' => UuidBehavior::class, ], ]; } }
in followed example uuid in active record will be filled with random UUIDv4 before inserting.