Download the PHP package mawuekom/laravel-model-uuid without Composer
On this page you can find all versions of the php package mawuekom/laravel-model-uuid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mawuekom/laravel-model-uuid
More information about mawuekom/laravel-model-uuid
Files in mawuekom/laravel-model-uuid
Package laravel-model-uuid
Short Description Easily work with UUIDs in your Laravel models
License MIT
Homepage https://github.com/mawuekom/laravel-model-uuid
Informations about the package laravel-model-uuid
Laravel Model UUIDs
A simple solution to easily work with UUIDs in your Laravel models.
This package provides a way to generate and work with RFC 4122 version 1, 2, 3, 4, and 5 universally unique identifiers (UUID). It also supports optional and non-standard features, such as [version 6 UUIDs], GUIDs, and other approaches for encoding/decoding UUIDs.
It based on ramsey/uuid package.
Take a look on this for more details.
What Is a UUID?
A universally unique identifier, or UUID, is a 128-bit unsigned integer, usually represented as a hexadecimal string split into five groups with dashes. The most widely-known and used types of UUIDs are defined by RFC 4122.
A UUID, when encoded in hexadecimal string format, looks like:
The probability of duplicating a UUID is close to zero, so they are a great choice for generating unique identifiers in distributed systems.
UUIDs can also be stored in binary format, as a string of 16 bytes.
It is suggested to use UUIDs in your responses instead of IDs, which are generally enumerable.
This will help mitigate some forms of enumeration attacks.
Note: This package explicitly does not disable auto-incrementing on your Eloquent models. In terms of database indexing, it is generally more efficient to use auto-incrementing integers for your internal querying. Indexing your uuid column will make lookups against that column fast, without impacting queries between related models.
Installation
You can install the package via composer:
Usage
To use this package, you simply need to import and use the trait within your Eloquent models.
It is assumed that you already have a field named uuid
in your database, which is used to store the generated value. If you wish to use a custom column name, for example if you want your primary id
column to be a UUID
, you can define a uuidColumn
method in your model.
You can have multiple UUID columns in each table by specifying an array in the uuidColumns
method. When querying using the whereUuid
scope, the default column - specified by uuidColumn
will be used.
By default, this package will use UUID version 4 values, however, you are welcome to use uuid1
, uuid3
, uuid4
, or uuid5
by specifying the protected property $uuidVersion
in your model. Should you wish to take advantage of ordered UUID (version 4) values that were introduced in Laravel 5.6, you should specify ordered
as the $uuidVersion
in your model.
This trait also provides a query scope which will allow you to easily find your records based on their UUID, and respects any custom field name you choose.
It also have methods
getIdFromUuid
: Retrieve auto-incrementing ID from UuidloadFromUuid
: Retrieve model data from Uuid
There is also ValidatesUuid
trait which as his name says validate incoming UUID before make model queries.
You can use it in your Controller too :
There is also a useful helper function is_the_given_id_a_uuid
that return true
if the given id is a uuid or false
if not.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-model-uuid with dependencies
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
ramsey/uuid Version ^4.1