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

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

alhaji-aki/laravel-uuid
=======================

Trait to generate uuid when creating models

1.0.3(4y ago)24.0k1[1 issues](https://github.com/alhaji-aki/laravel-uuid/issues)[1 PRs](https://github.com/alhaji-aki/laravel-uuid/pulls)1MITPHPPHP ^7.3|^8.0|^8.1

Since Oct 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/alhaji-aki/laravel-uuid)[ Packagist](https://packagist.org/packages/alhaji-aki/laravel-uuid)[ RSS](/packages/alhaji-aki-laravel-uuid/feed)WikiDiscussions main Synced yesterday

READMEChangelog (4)Dependencies (6)Versions (5)Used By (1)

Generate slugs when saving Eloquent models
==========================================

[](#generate-slugs-when-saving-eloquent-models)

[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Workflow Status](https://camo.githubusercontent.com/95352cd0bd263ae13a595916f196e6bffd1b3c821512883a7a9133560b9c3da2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f616c68616a692d616b692f6c61726176656c2d757569642f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/alhaji-aki/laravel-uuid/actions)

This package provides a trait that will generate a unique uuid when saving any Eloquent model.

```
$model = new EloquentModel();
$model->name = 'activerecord is awesome';
$model->save();
echo $model->uuid; // outputs a uuid
```

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

[](#installation)

You can install the package via composer:

```
composer require alhaji-aki/laravel-uuid
```

Usage
-----

[](#usage)

Your Eloquent models should use the `AlhajiAki\LaravelUuid\HasUuid` trait.

The trait contains an abstract method `getUuidColumn()` that you must implement yourself.

Your models' migrations should have a field to save the uuid to.

Here's an example of how to implement the trait:

```
namespace App;
use AlhajiAki\LaravelUuid\HasUuid;
use Illuminate\Database\Eloquent\Model;
class YourEloquentModel extends Model
{
    use HasUuid;

    /**
     * Get the column to save the generated uuid to.
     */
    public function getUuidColumn() : string
    {
        return 'uuid';
    }
}
```

With its migration:

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateYourEloquentModelTable extends Migration
{
    public function up()
    {
        Schema::create('your_eloquent_models', function (Blueprint $table) {
            $table->increments('id');
            $table->string('uuid'); // Field name same as what you return in `getUuidColumn`
            $table->string('name');
            $table->timestamps();
        });
    }
}
```

### Using slugs in routes

[](#using-slugs-in-routes)

To use the generated uuid in routes, remember to use Laravel's [implicit route model binding](https://laravel.com/docs/8.x/routing#implicit-binding):

```
namespace App;
use AlhajiAki\LaravelUuid\HasUuid;
use Illuminate\Database\Eloquent\Model;
class YourEloquentModel extends Model
{
    use HasUuid;

    /**
     * Get the column to save the generated uuid to.
     */
    public function getUuidColumn() : string
    {
        return 'uuid';
    }
    /**
     * Get the route key for the model.
     *
     * @return string
     */
    public function getRouteKeyName()
    {
        return 'uuid';
    }
}
```

### Overriding slugs

[](#overriding-slugs)

You can also override the generated slug just by setting it to another value than the generated slug.

```
$model = EloquentModel::create(['name' => 'my name']); //slug is now "my-name";
$model->slug = 'my-custom-url';
$model->save(); //slug is now "my-custom-url";
```

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

This package is inspired by [Spatie Laravel Sluggable](https://github.com/spatie/laravel-sluggable).

License
-------

[](#license)

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

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Every ~70 days

Total

4

Last Release

1464d ago

PHP version history (2 changes)v1.0.0PHP ^7.3|^8.0

1.0.3PHP ^7.3|^8.0|^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19788708?v=4)[Abdul Kudus](/maintainers/alhaji-aki)[@alhaji-aki](https://github.com/alhaji-aki)

---

Top Contributors

[![alhaji-aki](https://avatars.githubusercontent.com/u/19788708?v=4)](https://github.com/alhaji-aki "alhaji-aki (13 commits)")

---

Tags

laraveluuid

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[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)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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