leomarquine / eloquent-uuid by leomarquine

Uuid primary key for Laravel Eloquent Models
9,500
7
1
Package Data
Maintainer Username: leomarquine
Maintainer Contact: leonardomarquine@gmail.com (Leonardo Marquine)
Package Create Date: 2016-09-24
Package Last Update: 2020-03-11
Language: PHP
License: MIT
Last Refreshed: 2024-04-25 15:17:51
Package Statistics
Total Downloads: 9,500
Monthly Downloads: 79
Daily Downloads: 5
Total Stars: 7
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

Eloquent UUID

Uuid primary key for Laravel Eloquent Models.

Installation

Install through Composer

composer require marquine/eloquent-uuid

Usage

Database table

In your migration, create a column for the uuid primary key:

$table->uuid('id')->primary();

or

$table->string('id', 32)->primary();

If your primary key column name is not id, you need to set the model's $primaryKey property to the correct name.

Model

Use the Uuid trait in your model:

<?php

namespace App;

use Marquine\EloquentUuid\Uuid;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Uuid;
}

License

Eloquent UUID is licensed under the MIT license.