Skip to content

LaraStuffs/PrimaryUUID

Repository files navigation

LaraStuffs Primary UUID

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.

About

Use UUID as primary key on Laravel Models

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages