HasUUID trait

This commit is contained in:
bad 2021-10-28 11:19:27 +02:00
parent ba7dbed00c
commit 74000681fc
3 changed files with 15 additions and 2 deletions

View file

@ -12,13 +12,24 @@ use Illuminate\Support\Str;
*/
trait HasUUID
{
protected static function getPrimaryKey()
{
return self::uuidField();
}
/**
* Defines the UUID field for the model.
* @return string
*/
protected static function uuidField()
{
return 'id';
return 'uuid';
}
public function getIncrementing()
{
return false;
}
/**

View file

@ -9,6 +9,8 @@ use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable {
use HasApiTokens, HasFactory, HasUUID, Notifiable;
public $primaryKey = "uuid";
/**
* The attributes that are mass assignable.
*

View file

@ -14,7 +14,7 @@ class CreateUsersTable extends Migration
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->uuid("id")->unique()->primary();
$table->uuid("uuid")->unique()->primary();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();