#34 Generate UUID on seeder/models
This commit is contained in:
@@ -11,7 +11,10 @@ use Eloquent as Model;
|
||||
*/
|
||||
class Flight extends Model
|
||||
{
|
||||
use Uuids;
|
||||
|
||||
public $table = 'flights';
|
||||
public $incrementing = false;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
|
||||
@@ -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
21
app/Models/UuidTrait.php
Normal 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user