-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Using UUID/GUID for primary key on user table #489
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
Glad you got it working without any issues! Thanks for letting us know. |
@AlexVanderbist can u add this to the docs ? |
I think there is something missing on the doc. We need to update user model too.
|
@dashracer in my case it doesn't work with |
This is what I had to do in the top of my user model to make it work:
|
@miguelsmuller can you share your |
@drbyte Hi, I'm having the same problem as @miguelsmuller when using assignRole. I'm using UUID as primary key. Here's my config/permission.php:
Edit: I traced the code and the error happens on
I tried to comment that line and no errors show when doing assignRole. I tried doing Also, I'm only getting the error inside my seeder. On tinker, when I do assignRole, no error occurs. Last test is I added Any ideas why is this happening? |
Was any able to resolve this issue? I am experiencing the same thing as @miguelsmuller I have tried $user->refresh(); with no luck. The error also gets thrown when I user $user->syncRoles. Note that this error only occurs when I call I am call a new instance of User (creating a new user) I am able to update the users role with no issues. |
Same issue as the last 2 people. I'm having to comment out I replicated the 2 traits and called them within my User model, does anyone think this will cause issues other than making sure that I keep them up to date with any changes? |
Can you explain what error is being thrown when Understanding what the error is, and then digging into why that specific error is occurring, will lead to a better outcome. |
All you have to do is cast uuid as string. It will solve all your problems. $u = User::create([
'id' => (string)Str::uuid(),
'name' => 'Admin',
'email' => 'admin@example.com',
'password' => bcrypt('admin'),
'remember_token' => Str::random(60)
]);
$u->assignRole('Admin'); The problem comes for Str::uuid() that creates an object instead of a string. |
Not sure where to put this, but I am successfully using this using my UUID user IDs, in place of the integer IDs. Just wanted to document it publicly in case anyone else tries to do this.
I accomplished this by replacing every instance of
$table->morphs('model')
with:I am using GUIDs because my main authentication is linked with Active Directory (via Adldap2/Adldap2-Laravel), and I need to use the AD primary keys as my primary keys to ensure user relation integrity to active directory.
The text was updated successfully, but these errors were encountered: