paulhenri-l/laravel-has-uuid

1.0.1 2021-09-22 22:00 UTC

This package is auto-updated.

Last update: 2024-03-23 03:34:30 UTC


README

Tests License: MIT

Easily use uuids as the primary key for your eloquent models.

Installation

composer require paulhenri-l/laravel-has-uuid

Usage

This feature is provided as a trait that you should use in your models.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Hello extends Model
{
    use \PaulhenriL\LaravelHasUuid\HasUuid;
}

You should also use the uuid filed in your migrations instead of the default id one.

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

Now whenever you'll create a new model it will be given an uuid instead of an incrementing id