recycledbeans/eloquent-uuid

A quick and easy way to use UUID primary keys in Laravel Eloquent models.

v1.0.0 2020-08-12 23:21 UTC

This package is auto-updated.

Last update: 2024-12-20 09:49:10 UTC


README

A quick and easy way to use UUID primary keys in Laravel Eloquent models.

Installation

Simply require the package with composer to add it to your Laravel application.

composer require recycledbeans/eloquent-uuid

Usage

Make sure your migrations use the uuid() field type and that the field is set as the primary key.

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

Then use the UUID trait in your Eloquent models to ensure your models automatically function with UUID primary keys.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use RecycledBeans\EloquentUUID\UUID;

class Document extends Model
{
    use UUID;
}