2017 © Pedro Peláez
 

library eloquent-uuid

Trait to implement UUID in Eloquent ORM

image

juniorb2ss/eloquent-uuid

Trait to implement UUID in Eloquent ORM

  • Tuesday, August 8, 2017
  • by juniorb2s
  • Repository
  • 1 Watchers
  • 3 Stars
  • 2,043 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 36 % Grown

The README.md

Eloquent UUID Trait

Build Status Code Coverage Laravel Scrutinizer Code Quality StyleCI Code Climate, (*1)

The juniorb2ss/eloquent-uuid provider a simple trait to implement UUID to ORM., (*2)

Install

You can install this package via composer:, (*3)

``` bash $ composer require juniorb2ss/eloquent-uuid~1.*, (*4)


## Eloquent Trait ```php use juniorb2ss\EloquentUuid\EloquentUuidTrait; class User extends Authenticatable { use Notifiable, EloquentUuidTrait; /** * UUID Column name used * * @var string * @optional */ protected $uuidKey = 'uuid'; }

UUID Column

You need create new column in table model like uuid or custom name you can define in uuidKey model property, (*5)

Example

$fields = $request->only(['email', 'name', 'password']);
$user = User::create($fields); // Creating user with auto-inject uuid field

dump($user->toArray());

/*[
    "id" => "1"
    "uuid" => "723e4628-7c35-11e7-89b1-0242bfc0df57",
    "name" => "Magdalena Zboncak"
    "email" => "nitzsche.katherine@gulgowski.com"  
  ]*/

Scope On UUID

use App\User;

$user = (new User)->onUuid('aae5f3f1-0f22-4a8b-9291-d2a9649d1490')
                  ->firstOrFail();

Tests

composer run test

Change log

Please see CHANGELOG for more information on what has changed recently., (*6)

Credits

License

The MIT License (MIT). Please see License File for more information., (*7)

The Versions