-
Notifications
You must be signed in to change notification settings - Fork 846
Default team will not work if primary key for user changes from id() to uuid() #218
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
Comments
I think we only support regular id's but need confirmation by @taylorotwell. /cc @crynobone |
@AngelinCalu you can read this PR : #22 |
The fact that this actually works when creating the user though the registration form, and not when creating it from the model factory, it's an alarm signal that the problem is not about using uuid's or not, but about creating a new account workflow. From what I can see that's because in Is there something obvious that I'm maybe missing here? return DB::transaction(function () use ($input) {
return tap(User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]), function (User $user) {
$this->createTeam($user); // <- this part here
});
}); LE: after all this is only an inconvenience when writing tests, as in production everybody will eventually use the registration form to create a new account, thus creating that default team as shown above ☝️ |
For anyone else facing the same problem, my workaround was to manually create a personal team for each user created through the factory in the "seed-ing" process:
The downsides remaining:
|
We don't support UUIDs out of the box. |
@driesvints, @taylorotwell any changes now that this got merged? |
This is a massive bummer. It means you cannot use |
For any future travelers who stumble onto this issue, here is how I solved it (I'm using nano id, but uuid should work almost the same):
public function getRouteKeyName(): string
{
return 'nano_id';
}
use App\Models\Team;
use Illuminate\Http\Request;
use Laravel\Jetstream\Http\Controllers\Livewire\TeamController;
Route::group(['middleware' => config('jetstream.middleware', ['web'])], function () {
$authMiddleware = config('jetstream.guard')
? 'auth:'.config('jetstream.guard')
: 'auth';
$authSessionMiddleware = config('jetstream.auth_session', false)
? config('jetstream.auth_session')
: null;
Route::group(['middleware' => array_values(array_filter([$authMiddleware, $authSessionMiddleware]))], function () {
Route::group(['middleware' => 'verified'], function () {
Route::get('/teams/{team}', function (Request $request, Team $team) {
return app()->make(TeamController::class)->show($request, $team->id);
})->name('teams.show');
});
}); All the middleware, etc. is essentially a direct copy from the vendor file included in Jetstream. Then we just override the team-id dependent route, dereference the id after dependency injection (which will be resolved how we want thanks to the We're using Laravel's service container here to resolve the TeamController class, which is a little more idiomatic than instantiating the controller directly. Janky? Yes. Jankier than the alternatives? Meh, it's a matter of taste, but this feels ok to me. Hope it helps someone out there! |
Description:
When user registers through the form everything works perfectly.
When I'm trying to log in with a user created with:
I'm getting an
ErrorException Trying to get property 'id' of non-object
oncurrentTeam()
function from...\vendor\laravel\jetstream\src\HasTeams.php:28
Steps To Reproduce:
The text was updated successfully, but these errors were encountered: