diff --git a/app/Models/HasUUID.php b/app/Models/HasUUID.php index 4461479..53f526f 100644 --- a/app/Models/HasUUID.php +++ b/app/Models/HasUUID.php @@ -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; } /** diff --git a/app/Models/User.php b/app/Models/User.php index 242fedf..95c5be9 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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. * diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index d27db16..e90c432 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -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();