HasUUID trait
This commit is contained in:
parent
ba7dbed00c
commit
74000681fc
3 changed files with 15 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue