larastuffs/primary-uuid

Use UUID as primary key on Laravel Models

v0.3 2021-05-17 17:47 UTC

This package is auto-updated.

Last update: 2024-11-18 01:39:33 UTC


README

Packagist Version License

this package provides a simple interface for using UUID as a primary key in models

Requirements

  • PHP 7.2 or latest
  • Laravel 6.* | 7.* | 8.*

Installation

Require this package with composer using the following command:

composer require larastuffs/primary-uuid

Usage

Follow the instructions to adapt your models and migrations

Model Setup

<?php
use ...;
use LaraStuffs\PrimaryUUID\Eloquent\Concerns\UseUUIDAsPrimaryKey;

class MyModel extends Model {
 
    use UseUUIDAsPrimaryKey;
 
    ...
}

Migration Setup

<?php
Schema::create('table_name', function (Blueprint $table) {
    $table->uuid('id')->primary();
});

Possible incompatibilities

if you use closures to define your model events, I strongly recommend that you use model observers instead

Contributing

Contributions are more than welcome. Fork, improve and make a pull request. For bugs, ideas for improvement or other, please create an issue.