PHPackages                             laith-zraikat/yii2-uuid-behavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. laith-zraikat/yii2-uuid-behavior

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

laith-zraikat/yii2-uuid-behavior
================================

Yii2 behavior for automatically generating and formatting UUIDs for ActiveRecord models

v1.0.1(1y ago)1252MITPHP &gt;=7.3.0

Since Apr 2Compare

[ Source](https://github.com/laith-zraikat/yii2-uuid-behavior)[ Packagist](https://packagist.org/packages/laith-zraikat/yii2-uuid-behavior)[ RSS](/packages/laith-zraikat-yii2-uuid-behavior/feed)WikiDiscussions Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Yii2 UUID Behavior
==================

[](#yii2-uuid-behavior)

A Yii2 behavior for automatically generating and formatting UUIDs for ActiveRecord models.

Features
--------

[](#features)

- Automatically generates UUIDs for new records
- Supports both PHP-generated and MySQL-generated UUIDs
- Configurable UUID format (with or without dashes)
- Handles existing UUIDs and ensures proper formatting
- Optional UUID generation on record updates

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

```
composer require laith-zraikat/yii2-uuid-behavior

```

Usage
-----

[](#usage)

Attach the behavior to your ActiveRecord model:

```
use LaithZraikat\UUID\UUIDBehavior;

class MyModel extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            [
                'class' => UUIDBehavior::class,
                'attribute' => 'uuid', // the attribute that will store the UUID
                'method' => UUIDBehavior::METHOD_MYSQL, // or UUIDBehavior::METHOD_PHP
                'keepDashes' => true, // whether to keep dashes in the UUID
                'enableOnUpdate' => false, // whether to generate UUID on update
            ],
        ];
    }
}
```

Configuration Options
---------------------

[](#configuration-options)

OptionTypeDefaultDescription`attribute`string`'uuid'`The model attribute that will store the UUID`method`string`UUIDBehavior::METHOD_MYSQL`UUID generation method (`METHOD_MYSQL` or `METHOD_PHP`)`keepDashes`boolean`true`Whether to keep dashes in the UUID`enableOnUpdate`boolean`false`Whether to generate UUID on model updateUUID Generation Methods
-----------------------

[](#uuid-generation-methods)

### MySQL Method (`METHOD_MYSQL`)

[](#mysql-method-method_mysql)

Uses MySQL's `UUID()` function to generate UUIDs. This method:

- Has better performance and uniqueness guarantees
- Requires a database call to generate the UUID
- The UUID is only available after the record is saved

### PHP Method (`METHOD_PHP`)

[](#php-method-method_php)

Generates UUIDs using PHP's `mt_rand()` function. This method:

- Makes the UUID available before saving the record
- Works with any database backend
- Slightly less performant than the MySQL method

UUID Formatting
---------------

[](#uuid-formatting)

The behavior supports two UUID formats:

1. **Standard format** (with dashes): `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
2. **Compact format** (without dashes): `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`

Use the `keepDashes` option to control the format.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance46

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

412d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/faeef9e4acf01f8ef44a0f30d9e1a89bff38bcb38cab446ba8945df540253fbb?d=identicon)[laith-zraikat](/maintainers/laith-zraikat)

---

Top Contributors

[![soofdev](https://avatars.githubusercontent.com/u/1759030?v=4)](https://github.com/soofdev "soofdev (1 commits)")

---

Tags

uuidyii2extensionBehavior

### Embed Badge

![Health badge](/badges/laith-zraikat-yii2-uuid-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/laith-zraikat-yii2-uuid-behavior/health.svg)](https://phpackages.com/packages/laith-zraikat-yii2-uuid-behavior)
```

###  Alternatives

[sjaakp/yii2-taggable

Manage tags of ActiveRecord in Yii2.

3030.6k](/packages/sjaakp-yii2-taggable)[mdmsoft/yii2-autonumber

Auto number extension for the Yii framework

1830.9k](/packages/mdmsoft-yii2-autonumber)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
