New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

alhaji-aki/laravel-uuid

Trait to generate uuid when creating models
3,963 2

Larablocks Analysis

alhaji-aki/laravel-uuid works with Laravel 7, 8 and 9 (latest release 1.0.3, May 10, 2022), all past end of life (the last on Feb 6, 2024): no more fixes, even for security.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 7, 8 and 9, past end of life since Feb 6, 2024
  • No release in the last 12 months (last: May 10, 2022)
  • 1 downloads a month (needs 10,000)
  • 2 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: May 10, 2022.
  • No releases in the last 12 months.
  • First released: Oct 12, 2021.
  • Monthly downloads: 1.
  • 1 open issue on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 29, 2026.

Install
composer require alhaji-aki/laravel-uuid
Latest Version:1.0.3
PHP:^7.3|^8.0|^8.1
Laravel:7 · 8 · 9
License:MIT
Last Updated:May 10, 2022
Links: GitHub  ·  Packagist
Maintainer: alhaji-aki

Generate slugs when saving Eloquent models

MIT Licensed GitHub Workflow Status

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

You can install the package via composer:

composer require alhaji-aki/laravel-uuid

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

To use the generated uuid in routes, remember to use Laravel's implicit route model 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

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

composer test

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

This package is inspired by Spatie Laravel Sluggable.

License

The MIT License (MIT). Please see License File for more information.

Related Packages

stayallive/laravel-eloquent-uuid

Generate UUID for a Laravel Eloquent model attribute.

72,996 4
aryehraber/statamic-uuid

One of its kind; unlike anything else

33,503 3
marquine/eloquent-uuid

Uuid primary key for Laravel Eloquent Models

11,576 7
theprivateer/eloquent-uuid

UUID utility traits for Laravel

7,181 1
simlux/laravel-model-uuid

Make usage of UUID in laravel models easy.

130 0

Version History

Version Released PHP Laravel License
1.0.3 ^7.3|^8.0|^8.1 ^7.30|^8.0|^9.0 MIT
1.0.2 ^7.3|^8.0 ^7.30|^8.0 MIT
1.0.1 ^7.3|^8.0 ^7.30|^8.0 MIT
v1.0.0 ^7.3|^8.0 ^7.30|^8.0 MIT