laravel-permission icon indicating copy to clipboard operation
laravel-permission copied to clipboard

assignRole and syncRoles fail for model with ulid type id

Open francisnnumbi opened this issue 1 year ago • 1 comments

When I create a users table with id of ulid type, I get an issue with assigning role or permission to user.

The error states that :

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'model_id' at row 1 (SQL: insert into model_has_roles (model_id, model_ty pe, role_id) values (01hmhx0f95bbw2xg2t6vsxp65s, App\Models\User, 1))SQLSTATE[01000]: Warning: 1265 Data truncated for column 'model _id' at row 1 (SQL: insert into model_has_roles (model_id, model_type, role_id) values (01hmhx0f9q43g7zf3mxeywn64x, App\Models
User, 2))

When I check the create_permission_tables migration, I notice for exemple, at create model_has_roles table, the model_morph_key is of type unsignedBigInteger !

image

But when I decide to change the type to string, it works fine, like here. image

But I noticed at the same time, this issue is not there when using sqlite as database !

I know what I have done is a hack. Is there a better way of solving this issue ?

francisnnumbi avatar Jan 19 '24 22:01 francisnnumbi

Are there some parts of this article in the documentation that may help? https://spatie.be/docs/laravel-permission/v6/advanced-usage/uuid

drbyte avatar Jan 20 '24 00:01 drbyte

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

spatie-bot avatar May 21 '24 10:05 spatie-bot