You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I've just tried to integrate this package into the Laravel 8 project using UUIDs implementation as a Primary Key. Everything looks fine until I try to assign a user to a certain role, e.g 'Admin'. My code:
It looks like the String casting doesn't work like expected. Because the role id still an integer value. And when I tried to implement the String casting in the original Spatie's Role model, everything works fine then. But, I wonder why it works fine when assigning permission to a user which is I thought has a similar case.
So, if you guys know how to solve this issue without touching the original package please let me know. Thanks.
The text was updated successfully, but these errors were encountered:
Hi,
I've just tried to integrate this package into the Laravel 8 project using UUIDs implementation as a Primary Key. Everything looks fine until I try to assign a user to a certain role, e.g 'Admin'. My code:
$user = $request->user(); $assignUserToRole = $user->assignRole('Admin');
and I got the following error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
laravel8_bootstrapdb.
model_has_roles, CONSTRAINT
model_has_roles_role_id_foreignFOREIGN KEY (
role_id) REFERENCES
roles(
id) ON DELETE CASCADE) (SQL: insert into
model_has_roles(
model_id,
model_type,
role_id) values (91b57341-5e99-4057-9b94-826a76579d16, App\Models\User, 91))
My own Role model that extends the Spatie's Role model:
`<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Str;
use App\Models\Concerns\UsesUuid;
class Role extends \Spatie\Permission\Models\Role
{
use HasFactory, UsesUuid;
}
`
It looks like the String casting doesn't work like expected. Because the role id still an integer value. And when I tried to implement the String casting in the original Spatie's Role model, everything works fine then. But, I wonder why it works fine when assigning permission to a user which is I thought has a similar case.
So, if you guys know how to solve this issue without touching the original package please let me know. Thanks.
The text was updated successfully, but these errors were encountered: