From 0d3145ca7218e49866759acf45fe4606ea3f694c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 2 Sep 2020 09:20:12 -0500 Subject: [PATCH 1/2] use numeric ids for users --- .../2014_10_12_000000_create_users_table.php | 2 +- .../2020_05_21_100000_create_teams_table.php | 2 +- ...20_05_21_200000_create_team_user_table.php | 2 +- src/Console/InstallCommand.php | 12 --------- src/HasTeams.php | 2 +- .../Inertia/TeamMemberController.php | 4 +-- src/Http/Livewire/TeamMemberManager.php | 6 ++--- src/Jetstream.php | 4 +-- stubs/app/Models/User.php | 27 ------------------- stubs/app/Models/UserWithTeams.php | 27 ------------------- tests/Fixtures/User.php | 26 ------------------ 11 files changed, 11 insertions(+), 103 deletions(-) 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 87ae74cef..1f66d84b9 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')->primary(); + $table->id(); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); diff --git a/database/migrations/2020_05_21_100000_create_teams_table.php b/database/migrations/2020_05_21_100000_create_teams_table.php index d139e80f7..84799c3f1 100644 --- a/database/migrations/2020_05_21_100000_create_teams_table.php +++ b/database/migrations/2020_05_21_100000_create_teams_table.php @@ -15,7 +15,7 @@ public function up() { Schema::create('teams', function (Blueprint $table) { $table->uuid('id')->primary(); - $table->uuid('user_id')->index(); + $table->foreignId('user_id')->index(); $table->string('name'); $table->boolean('personal_team'); $table->timestamps(); diff --git a/database/migrations/2020_05_21_200000_create_team_user_table.php b/database/migrations/2020_05_21_200000_create_team_user_table.php index 888705cbf..a3c6ef869 100644 --- a/database/migrations/2020_05_21_200000_create_team_user_table.php +++ b/database/migrations/2020_05_21_200000_create_team_user_table.php @@ -16,7 +16,7 @@ public function up() Schema::create('team_user', function (Blueprint $table) { $table->id(); $table->uuid('team_id'); - $table->uuid('user_id'); + $table->foreignId('user_id'); $table->string('role')->nullable(); $table->timestamps(); diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index ee7fa90bf..db329af4b 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -98,14 +98,6 @@ protected function configureSession() $this->replaceInFile("'SESSION_DRIVER', 'file'", "'SESSION_DRIVER', 'database'", config_path('session.php')); $this->replaceInFile('SESSION_DRIVER=file', 'SESSION_DRIVER=database', base_path('.env')); $this->replaceInFile('SESSION_DRIVER=file', 'SESSION_DRIVER=database', base_path('.env.example')); - - foreach ((new Filesystem)->files(database_path('migrations')) as $file) { - if (Str::contains($file->getRealPath(), 'create_sessions_table')) { - $this->replaceInFile("foreignId('user_id')", "uuid('user_id')", $file->getRealPath()); - - break; - } - } } /** @@ -127,8 +119,6 @@ protected function installLivewireStack() $this->output->write($output); }); - $this->replaceInFile('morphs', 'uuidMorphs', database_path('migrations/2019_12_14_000001_create_personal_access_tokens_table.php')); - // Update Configuration... $this->replaceInFile('inertia', 'livewire', config_path('jetstream.php')); $this->replaceInFile("'guard' => 'web'", "'guard' => 'sanctum'", config_path('auth.php')); @@ -274,8 +264,6 @@ protected function installInertiaStack() $this->output->write($output); }); - $this->replaceInFile('morphs', 'uuidMorphs', database_path('migrations/2019_12_14_000001_create_personal_access_tokens_table.php')); - // Update Configuration... $this->replaceInFile("'guard' => 'web'", "'guard' => 'sanctum'", config_path('auth.php')); diff --git a/src/HasTeams.php b/src/HasTeams.php index 87e398c4a..8909cd9a5 100644 --- a/src/HasTeams.php +++ b/src/HasTeams.php @@ -80,7 +80,7 @@ public function personalTeam() */ public function ownsTeam($team) { - return $this->id === $team->user_id; + return (int) $this->id === (int) $team->user_id; } /** diff --git a/src/Http/Controllers/Inertia/TeamMemberController.php b/src/Http/Controllers/Inertia/TeamMemberController.php index a6ee4cd1c..f1688c610 100644 --- a/src/Http/Controllers/Inertia/TeamMemberController.php +++ b/src/Http/Controllers/Inertia/TeamMemberController.php @@ -37,7 +37,7 @@ public function store(Request $request, $teamId) * * @param \Illuminate\Http\Request $request * @param string $teamId - * @param string $userId + * @param int $userId * @return \Illuminate\Http\RedirectResponse */ public function update(Request $request, $teamId, $userId) @@ -57,7 +57,7 @@ public function update(Request $request, $teamId, $userId) * * @param \Illuminate\Http\Request $request * @param string $teamId - * @param string $userId + * @param int $userId * @return \Illuminate\Http\RedirectResponse */ public function destroy(Request $request, $teamId, $userId) diff --git a/src/Http/Livewire/TeamMemberManager.php b/src/Http/Livewire/TeamMemberManager.php index 7d3ebf088..6bd829ee3 100644 --- a/src/Http/Livewire/TeamMemberManager.php +++ b/src/Http/Livewire/TeamMemberManager.php @@ -56,7 +56,7 @@ class TeamMemberManager extends Component /** * The ID of the team member being removed. * - * @var string|null + * @var int|null */ public $teamMemberIdBeingRemoved = null; @@ -111,7 +111,7 @@ public function addTeamMember(AddsTeamMembers $adder) /** * Allow the given user's role to be managed. * - * @param string $userId + * @param int $userId * @return void */ public function manageRole($userId) @@ -173,7 +173,7 @@ public function leaveTeam(RemoveTeamMember $remover) /** * Confirm that the given team member should be removed. * - * @param string $userId + * @param int $userId * @return void */ public function confirmTeamMemberRemoval($userId) diff --git a/src/Jetstream.php b/src/Jetstream.php index 031c55176..488577e59 100644 --- a/src/Jetstream.php +++ b/src/Jetstream.php @@ -160,9 +160,9 @@ public static function hasTeamFeatures() /** * Find a user instance by the given ID. * - * @param string $id + * @param int $id */ - public static function findUserByIdOrFail(string $id) + public static function findUserByIdOrFail($id) { return static::newUserModel()->where('id', $id)->firstOrFail(); } diff --git a/stubs/app/Models/User.php b/stubs/app/Models/User.php index 0be0c32f6..d1b54f6df 100644 --- a/stubs/app/Models/User.php +++ b/stubs/app/Models/User.php @@ -5,7 +5,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -use Illuminate\Support\Str; use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Jetstream\HasProfilePhoto; use Laravel\Sanctum\HasApiTokens; @@ -18,20 +17,6 @@ class User extends Authenticatable use Notifiable; use TwoFactorAuthenticatable; - /** - * The "type" of the primary key ID. - * - * @var string - */ - protected $keyType = 'string'; - - /** - * Indicates if the IDs are auto-incrementing. - * - * @var bool - */ - public $incrementing = false; - /** * The attributes that are mass assignable. * @@ -72,16 +57,4 @@ class User extends Authenticatable protected $appends = [ 'profile_photo_url', ]; - - /** - * Handle the model "booted" event. - * - * @return void - */ - public static function booted() - { - static::creating(function ($model) { - $model->id = $model->id ?: (string) Str::orderedUuid(); - }); - } } diff --git a/stubs/app/Models/UserWithTeams.php b/stubs/app/Models/UserWithTeams.php index 2408b5dc2..5b9f03f4f 100644 --- a/stubs/app/Models/UserWithTeams.php +++ b/stubs/app/Models/UserWithTeams.php @@ -5,7 +5,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -use Illuminate\Support\Str; use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Jetstream\HasProfilePhoto; use Laravel\Jetstream\HasTeams; @@ -20,20 +19,6 @@ class User extends Authenticatable use Notifiable; use TwoFactorAuthenticatable; - /** - * The "type" of the primary key ID. - * - * @var string - */ - protected $keyType = 'string'; - - /** - * Indicates if the IDs are auto-incrementing. - * - * @var bool - */ - public $incrementing = false; - /** * The attributes that are mass assignable. * @@ -72,16 +57,4 @@ class User extends Authenticatable protected $appends = [ 'profile_photo_url', ]; - - /** - * Handle the model "booted" event. - * - * @return void - */ - public static function booted() - { - static::creating(function ($model) { - $model->id = $model->id ?: (string) Str::orderedUuid(); - }); - } } diff --git a/tests/Fixtures/User.php b/tests/Fixtures/User.php index 4127175c9..e8ae34d5d 100644 --- a/tests/Fixtures/User.php +++ b/tests/Fixtures/User.php @@ -11,36 +11,10 @@ class User extends Authenticatable { use HasApiTokens, HasTeams; - /** - * The "type" of the primary key ID. - * - * @var string - */ - protected $keyType = 'string'; - - /** - * Indicates if the IDs are auto-incrementing. - * - * @var bool - */ - public $incrementing = false; - /** * The attributes that aren't mass assignable. * * @var array */ protected $guarded = []; - - /** - * Handle the model "booted" event. - * - * @return void - */ - public static function booted() - { - static::creating(function ($model) { - $model->id = $model->id ?: (string) Str::orderedUuid(); - }); - } } From 5db347b6472c4ce12f696edf601d01f76990a5fc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 2 Sep 2020 09:20:33 -0500 Subject: [PATCH 2/2] Apply fixes from StyleCI (#21) --- tests/Fixtures/User.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Fixtures/User.php b/tests/Fixtures/User.php index e8ae34d5d..3671f3069 100644 --- a/tests/Fixtures/User.php +++ b/tests/Fixtures/User.php @@ -3,7 +3,6 @@ namespace Laravel\Jetstream\Tests\Fixtures; use Illuminate\Foundation\Auth\User as Authenticatable; -use Illuminate\Support\Str; use Laravel\Jetstream\HasTeams; use Laravel\Sanctum\HasApiTokens;