Replies: 1 comment 1 reply
-
If you're open to it, I'd be happy to help make this package more flexible to support both UUID and bigint-based models out-of-the-box. Whether through a pull request or contributing on specific parts, feel free to reach out — I'd be glad to collaborate and ensure smooth support for both ID types in future versions. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Support UUID and Bigint in spatie/laravel-permission
model_id
🐛 Problem Overview
When using
spatie/laravel-permission
in projects with UUID-based primary keys (such asusers.id
being auuid
), a type mismatch error occurs due to the default database migration assumingmodel_id
is anunsignedBigInteger
.❌ Example Error
This happens because the default migrations define
model_id
(viamodel_morph_key
) as:This causes a fatal mismatch when UUIDs are used.
✅ Recommended Solution
Change the column type for
model_morph_key
(model_id
) tostring
instead ofunsignedBigInteger
.✅ Updated Migration Snippet
Replace:
With:
This allows UUIDs like
01984de3-23bb-7189-9ff3-c4a343bebb33
and also integer-based IDs like1
or42
.💡 Why This Matters
This allows
spatie/laravel-permission
to:🧩 Alternative Options
If you're using only UUIDs, you could define the column as
uuid
instead:However, this won't support
bigint
IDs, sostring
is the most flexible option.🙏 Final Note
Thanks again for the amazing package. We hope this improvement can be considered to support more Laravel use cases out-of-the-box.
@tikrack
Beta Was this translation helpful? Give feedback.
All reactions