Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use numeric ids for users #22

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 0 additions & 12 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

/**
Expand All @@ -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'));
Expand Down Expand Up @@ -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'));

Expand Down
2 changes: 1 addition & 1 deletion src/HasTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Inertia/TeamMemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Livewire/TeamMemberManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Jetstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
27 changes: 0 additions & 27 deletions stubs/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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();
});
}
}
27 changes: 0 additions & 27 deletions stubs/app/Models/UserWithTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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();
});
}
}
27 changes: 0 additions & 27 deletions tests/Fixtures/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,17 @@
namespace Laravel\Jetstream\Tests\Fixtures;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Str;
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;

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();
});
}
}