nevadskiy/laravel-uuid

This package is abandoned and no longer maintained. No replacement package was suggested.

The package provides UUID keys functionality for Eloquent models with one single trait.

1.2.1 2022-06-20 08:59 UTC

This package is auto-updated.

Last update: 2023-05-20 11:07:54 UTC


README

Stand With Ukraine

Laravel UUIDs

Latest Stable Version Tests Code Coverage License

The package allows models to use UUID primary keys with one single trait.

Installation

Install a package via composer.

composer require nevadskiy/laravel-uuid

Usage

Add a trait to your model, and it will automatically assign a UUID key to the model during creation.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Nevadskiy\Uuid\Uuid;

class Product extends Model
{
    use Uuid;
}

Set up migrations to use UUID primary keys.

Schema::create('products', function (Blueprint $table) {
    $table->uuid('id')->primary();
});

Recommendations

Set up the default field type for database migrations when using the morphs method.

public function boot(): void
{
    Builder::morphsUsingUuid();
}

You can also use the parameter expression constraints for routes that use a route model binding.

Route::get('/products/{product}', '...')->whereUuid('product')

Requirements

  • Laravel 6.0 or newer
  • PHP 7.2 or newer

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Any contribution is Welcome.

Please see CONTRIBUTING for more information.

Security

If you discover any security related issues, please e-mail me instead of using the issue tracker.

License

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