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-10-29 05:53:43 UTC
README
A Laravel package for creating uuid primary keys.
How to use?
- Install
composer require haymetg/luuid
- 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();
});
- 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