#34 Generate UUID on seeder/models

This commit is contained in:
Nabeel Shahzad
2017-06-24 13:20:24 -05:00
parent 2aa7cc66d5
commit ba57cef0a7
9 changed files with 103 additions and 14 deletions

View File

@@ -11,7 +11,10 @@ use Eloquent as Model;
*/
class Flight extends Model
{
use Uuids;
public $table = 'flights';
public $incrementing = false;
protected $dates = ['deleted_at'];

View File

@@ -31,6 +31,7 @@ use Illuminate\Contracts\Auth\CanResetPassword;
*/
class User extends Authenticatable
{
use Uuids;
use Notifiable;
use EntrustUserTrait;

21
app/Models/UuidTrait.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Webpatser\Uuid\Uuid;
trait Uuids
{
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$key = $model->getKeyName();
if (empty($model->{$key})) {
$model->{$key} = Uuid::generate()->string;
}
#$model->{$model->getKeyName()} = Uuid::generate()->string;
});
}
}