haymetg/luuid

A Laravel package for making UUID primary key

1.0.1 2020-06-30 00:34 UTC

This package is auto-updated.

Last update: 2024-05-29 04:41:49 UTC


README

A Laravel package for creating uuid primary keys.

How to use?

  1. Install composer require haymetg/luuid
  2. use luuid() in migration,

Example:

Schema::create('posts', function (Blueprint  $table) {
    $table->luuid(); // you can also custom your luuid `luuid('post_id')`
    $table->string('title');
    $table->string('body');
    $table->timestamps();
});
  1. use WithUuid trait in your Model and declare the primary key

Example:

namespace  App;

use HaymeTG\LUUID\Traits\WithUuid;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
	use WithUuid;
	protected $primaryKey = 'uuid';
}

Done! This will automatically generate unique UUID whenever you save a new record.

Credits:

Liam-senpai https://github.com/liamdemafelix