PHPackages                             leganz/laravel-uuid - 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. leganz/laravel-uuid

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

leganz/laravel-uuid
===================

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

v1.3.4(5y ago)02.9kMITPHPPHP ~5.6|~7.0|^8.0

Since Feb 14Pushed 5y agoCompare

[ Source](https://github.com/leganz/laravel-uuid)[ Packagist](https://packagist.org/packages/leganz/laravel-uuid)[ Docs](https://github.com/emadadly/laravel-uuid)[ RSS](/packages/leganz-laravel-uuid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (19)Used By (0)

Laravel Uuid
============

[](#laravel-uuid)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2729472747898d3b7c64dc1ff26a9440cdc7aed6423675e0a62240d2a2f4f15b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656d616461646c792f6c61726176656c2d757569642e737667)](https://packagist.org/packages/emadadly/laravel-uuid)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/87b464e9baa97b234bf4738975ac1a1c7111df01fc5589560a686510c021050c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f656d616461646c792f6c61726176656c2d757569642e737667)](https://scrutinizer-ci.com/g/emadadly/laravel-uuid)[![Total Downloads](https://camo.githubusercontent.com/35133dfa87a1c28f4df1903c977785a21a6dde96f075cf9b6e93e1fcd8fe735e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656d616461646c792f6c61726176656c2d757569642e737667)](https://packagist.org/packages/emadadly/laravel-uuid)

A simple, automatic UUID generator for any model based on Laravel 5.5 and above, By using this package when each new entry you will get the following :

- Generate `uuid` automatically .
- Assign it to `uuid` field in database automatically.
- easy find it based `uuid` method.

### What is a UUID?

[](#what-is-a-uuid)

A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. is a 36 character long identifier made up of 32 alphanumeric characters with four hyphens in amongst it. For example:`123E4567-E89b-12D3-A456-426655440000` containing letters and numbers. that will uniquely identify something. you can read more [here](https://en.wikipedia.org/wiki/Universally_unique_identifier)

### What are the benefits?

[](#what-are-the-benefits)

1. With distributed systems you can be pretty confident that the primary key’s will never collide.
2. When building a large scale application when an auto increment primary key is not ideal.
3. It makes replication trivial (as opposed to int’s, which makes it REALLY hard)
4. Safe enough doesn’t show the user that you are getting information by id, for example `https://example.com/user/25/settings`

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

[](#installation)

To get started, require this package

- Via Composer

```
 composer require emadadly/laravel-uuid
```

- Via composer.json file

Add the following to the `require` section of your projects `composer.json` file.

```
"emadadly/laravel-uuid": "1.*",
```

Run composer update to download the package

```
 composer update
```

Finally, you'll also need to add the ServiceProvider

**Laravel 5.5 and above**

Uses package auto discovery feature, no need to edit the config/app.php file.

**Laravel 5.4 and below**

You need to add the ServiceProvider in `config/app.php` with the following

```
'providers' => [
   ...
   Emadadly\LaravelUuid\LaravelUuidServiceProvider::class,
],
```

You could also publish the config file:

```
php artisan vendor:publish --provider="Emadadly\LaravelUuid\LaravelUuidServiceProvider"
```

and set your default\_uuid\_column setting, if you have an app-wide default.

Our package assumes the column is `uuid` by default. If you want to replace the default `id` follow [these steps.](#replacing-default-id-with-uuid)

Usage
-----

[](#usage)

#### Migrations

[](#migrations)

When using the migration you should add `uuid` as column type, and set the name it the same name in the `config/uuid.php` file.

```
$table->uuid('uuid');
```

it's will create column uuid name and a char(36) inside of our database schema, To be ready to receive Uuids.

> Simply, the schema seems something like this.

```
Schema::create('users', function (Blueprint $table) {

  $table->increments('id');
  $table->uuid('uuid');
  ....
  ....
  $table->timestamps();
});
```

#### Models

[](#models)

Use this trait in any model.

To set up a model to using Uuid, simply use the Uuids trait:

```
use Illuminate\Database\Eloquent\Model;
use Emadadly\LaravelUuid\Uuids;

class ExampleModel extends Model
{
  use Uuids;
  ....
}
```

#### Controller

[](#controller)

When you create a new instance of a model which uses Uuids, our package will automatically add Uuid.

```
// 'Uuid' will automatically generate and assign id field.
$model = ExampleModel::create(['name' => 'whatever']);
```

Also when use show, update or delete method inside the Controller, it very easy to implement through `ExampleModel::uuid()` scope method

```
public function show($uuid)
{
  $example = ExampleModel::uuid($uuid);
  return response()->json(['example' => $example]);
}
```

#### Replacing default ID with UUID

[](#replacing-default-id-with-uuid)

If you want to replace the default id column with the uuid be sure to set `'default_uuid_column' => 'uuid',` to `'default_uuid_column' => 'id',` in the `config\uuid.php` file.

On your migration(s), change the id column type from `increments` to `uuid` as well as manually adding the primary key. *Note: This also applies to model relationship columns, if the related model is using an UUID, the column type should reflect that*

```
Schema::create('users', function (Blueprint $table) {

  $table->uuid('id')->unique();
  $table->primary('id');
  ....
  // related model uses UUID, must change type
  $table->uuid('model_id');
  ....
  $table->timestamps();
});
```

Then on the model(s) you will need to set the incrementing flag to false.

```
use Illuminate\Database\Eloquent\Model;
use Emadadly\LaravelUuid\Uuids;

class ExampleModel extends Model
{
  use Uuids;
  ....

  /**
  * Indicates if the IDs are auto-incrementing.
  *
  * @var bool
  */
  public $incrementing = false;

  ....
}
```

Support
-------

[](#support)

If you are having general issues with this package, feel free to contact me on [Twitter](https://twitter.com/emadadly).

If you believe you have found an issue, please report it using the [GitHub issue tracker](https://github.com/EmadAdly/laravel-uuid/issues), or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts. Thanks!

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 70.6% 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

Every ~82 days

Recently: every ~98 days

Total

18

Last Release

1972d ago

PHP version history (2 changes)v1.0PHP ~5.6|~7.0

v1.3.4PHP ~5.6|~7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/80b1e9efacc425a65161eda871719db5a51d598f46e3afc5455009a889c1483a?d=identicon)[sushidev](/maintainers/sushidev)

---

Top Contributors

[![EmadAdly](https://avatars.githubusercontent.com/u/5786899?v=4)](https://github.com/EmadAdly "EmadAdly (36 commits)")[![JeffBeltran](https://avatars.githubusercontent.com/u/22965241?v=4)](https://github.com/JeffBeltran "JeffBeltran (5 commits)")[![zagreusinoz](https://avatars.githubusercontent.com/u/16147285?v=4)](https://github.com/zagreusinoz "zagreusinoz (3 commits)")[![leganz](https://avatars.githubusercontent.com/u/3373530?v=4)](https://github.com/leganz "leganz (3 commits)")[![diadal](https://avatars.githubusercontent.com/u/19895516?v=4)](https://github.com/diadal "diadal (1 commits)")[![danherd](https://avatars.githubusercontent.com/u/659658?v=4)](https://github.com/danherd "danherd (1 commits)")[![b0gok](https://avatars.githubusercontent.com/u/4283162?v=4)](https://github.com/b0gok "b0gok (1 commits)")[![DougSisk](https://avatars.githubusercontent.com/u/70512?v=4)](https://github.com/DougSisk "DougSisk (1 commits)")

---

Tags

laravelgeneratoruuidguidlaravel-uuidemadadlylaravel-guid

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/leganz-laravel-uuid/health.svg)

```
[![Health](https://phpackages.com/badges/leganz-laravel-uuid/health.svg)](https://phpackages.com/packages/leganz-laravel-uuid)
```

###  Alternatives

[emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

120415.9k3](/packages/emadadly-laravel-uuid)[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.3M129](/packages/webpatser-laravel-uuid)[dcblogdev/laravel-module-generator

Generate Laravel Modules from a template.

7710.1k1](/packages/dcblogdev-laravel-module-generator)[linkxtr/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

295.1k](/packages/linkxtr-laravel-qrcode)[akira/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

431.4k](/packages/akira-laravel-qrcode)

PHPackages © 2026

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