项目作者: juniorb2ss

项目描述 :
Trait to implement UUID in Eloquent ORM
高级语言: PHP
项目地址: git://github.com/juniorb2ss/EloquentUuid.git
创建时间: 2017-08-07T18:43:10Z
项目社区:https://github.com/juniorb2ss/EloquentUuid

开源协议:MIT License

下载


Eloquent UUID Trait

Build Status Code Coverage Laravel Scrutinizer Code Quality StyleCI Code Climate

The juniorb2ss/eloquent-uuid provider a simple trait to implement UUID to ORM.

Install

You can install this package via composer:

  1. $ composer require juniorb2ss/eloquent-uuid~1.*

Eloquent Trait

  1. use juniorb2ss\EloquentUuid\EloquentUuidTrait;
  2. class User extends Authenticatable
  3. {
  4. use Notifiable, EloquentUuidTrait;
  5. /**
  6. * UUID Column name used
  7. *
  8. * @var string
  9. * @optional
  10. */
  11. protected $uuidKey = 'uuid';
  12. }

UUID Column

You need create new column in table model like uuid or custom name you can define in uuidKey model property

Example

  1. $fields = $request->only(['email', 'name', 'password']);
  2. $user = User::create($fields); // Creating user with auto-inject uuid field
  3. dump($user->toArray());
  4. /*[
  5. "id" => "1"
  6. "uuid" => "723e4628-7c35-11e7-89b1-0242bfc0df57",
  7. "name" => "Magdalena Zboncak"
  8. "email" => "nitzsche.katherine@gulgowski.com"
  9. ]*/

Scope On UUID

  1. use App\User;
  2. $user = (new User)->onUuid('aae5f3f1-0f22-4a8b-9291-d2a9649d1490')
  3. ->firstOrFail();

Tests

  1. composer run test

Change log

Please see CHANGELOG for more information on what has changed recently.

Credits

License

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