binarycabin/laravel-uuid

A wrapper for webpatser/laravel-uuid with additional integration
685,289 86
Install
composer require binarycabin/laravel-uuid
Latest Version:1.0.2
License:MIT
Last Updated:Apr 25, 2024
Links: GitHub  ·  Packagist
Maintainer: binarycabin

Laravel-UUID

Build Status StyleCI Latest Stable Version Total Downloads

A wrapper for webpatser/laravel-uuid with additional integration

composer require binarycabin/laravel-uuid

This package adds a very simple trait to automatically generate a UUID for your Models.

Simply add the "\BinaryCabin\LaravelUUID\Traits\HasUUID;" trait to your model:

<?php

namespace App;

use BinaryCabin\LaravelUUID\Traits\HasUUID;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{

    use HasUUID;

}

If your column name is not "uuid", simply add a new property to your model named "uuidFieldName":

protected $uuidFieldName = 'unique_id';

This trait also adds a scope:

\App\Project::byUUID('uuid')->first();

And static find method:

\App\Project::findByUUID('uuid')

A second trait is available if you use your UUIDs as primary keys:

<?php

namespace App;

use BinaryCabin\LaravelUUID\Traits\HasUUID;
use BinaryCabin\LaravelUUID\Traits\UUIDIsPrimaryKey;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{

    use HasUUID, UUIDIsPrimaryKey;

}

It simply tells Laravel that your primary key isn't an auto-incrementing integer, so it will treat the value correctly.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

598,760,099 34,966
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

399,241,428 4,660

Version History

Version Released License
1.0.2 MIT
1.0.1 MIT
1.0.0 MIT