Upgrade Essentials
All upgrades of this package should follow these steps:Update Migrations
Compare the migration file stubs in the new version against migrations you’ve already run. If necessary, create a new migration by hand to apply database changes.
Update Config File
Incorporate any changes to the
permission.php config file:- Backup your existing config
- Re-publish from the package
- Re-apply your customizations
Update Custom Models
If you’ve extended package models into your app, compare old and new models and apply relevant updates.
Update Custom Methods
If you’ve overridden any methods from package traits, compare old and new traits and apply updates.
Check Contracts
If you’ve implemented package contracts in any models, verify method signatures match.
Review Changelog
Review the Changelog for all changes.
Upgrading from v6 to v7
Version 7 modernizes the codebase while keeping the upgrade path relatively easy. Most changes are internal improvements.
Requirements
- PHP: 8.4 or higher
- Laravel: 12 or higher
- Test Suite: Now uses Pest 3.0
Breaking Changes
Event Class Renames
Event Class Renames
All event classes now have an
Action Required: Update your event listeners:
Event suffix for better clarity:| v6 Class | v7 Class |
|---|---|
PermissionAttached | PermissionAttachedEvent |
PermissionDetached | PermissionDetachedEvent |
RoleAttached | RoleAttachedEvent |
RoleDetached | RoleDetachedEvent |
Command Class Renames
Command Class Renames
All command classes now have a
Command suffix:| v6 Class | v7 Class |
|---|---|
CacheReset | CacheResetCommand |
CreateRole | CreateRoleCommand |
CreatePermission | CreatePermissionCommand |
Show | ShowCommand |
UpgradeForTeams | UpgradeForTeamsCommand |
AssignRole | AssignRoleCommand |
The artisan command signatures remain unchanged, so your scripts and code that call them via artisan continue to work.
Service Provider Changes
Service Provider Changes
The service provider now extends
PackageServiceProvider from spatie/laravel-package-tools.Lumen Support Removed: Version 7 no longer supports Lumen. Continue using v6 if you need Lumen.Removed Deprecated Methods
Removed Deprecated Methods
PermissionRegistrar::clearClassPermissions()has been removed- Use
clearPermissionsCollection()instead
Type Hints Added
Type Hints Added
Return types and parameter types have been added throughout. If you’ve extended classes or traits, update your method signatures:HasPermissions trait:HasRoles trait:PermissionRegistrar:
Wildcard Contract Changes
Wildcard Contract Changes
The
__construct(Model $record) method has been removed from the Spatie\Permission\Contracts\Wildcard interface.If you implement this contract, remove the constructor from interface requirements (your concrete class should still accept a Model in its constructor).Code Modernization
v7 includes internal code modernization that shouldn’t affect most users:- Constructor promotion in
WildcardPermission - Modern PHP syntax throughout (
instanceof,::class,str_contains) - Improved type safety
- Better use of imports
Upgrading from v5 to v6
Breaking Changes
ID Parameter Type Changes
ID Parameter Type Changes
Due to improved UUID/ULID/GUID support, methods accepting Permission or Role The Solution:
Convert string IDs to integers, especially when receiving from HTML forms:
id must receive integers, not numeric strings.The Problem:This primarily affects UI pages where HTML form data is received as strings.
Model Method Changes
Model Method Changes
If you’ve overridden
getPermissionClass() or getRoleClass() methods:- These methods now return strings, not instances
- Use
::syntax instead of->when accessing the model
Migration Updates Required
Migration Updates Required
Middleware Namespace Change
Middleware Namespace Change
The middleware namespace changed from plural to singular:Update in app/Http/Kernel.php (Laravel 10 and below):
RoleOrPermissionMiddleware Behavior Change
RoleOrPermissionMiddleware Behavior Change
The
RoleOrPermissionMiddleware now uses canAny() for checking abilities, which includes all abilities registered by your application (not just this package’s permissions).This may grant access to abilities like “Super Admin” that previously would have failed.Test Suite Changes
Test Suite Changes
If your tests manually register permissions, remove calls to
registerPermissions():New Features in v6
- Full UUID/ULID/GUID support
@haspermissionBlade directivewithoutRoleandwithoutPermissionquery scopes- Guard name included in exceptions
- BackedEnum support for roles and permissions
- Improved Laravel Octane support
- Performance improvements for wildcard permissions
Upgrading from v4 to v5
Follow the “Upgrade Essentials” steps at the top of this page. No major breaking changes between v4 and v5.Upgrading from v3 to v4
Breaking Changes
- Laravel 5.8 support dropped - Requires Laravel 6.0+
- PHP 7.2.5+ required (was 7.1)
- Unique constraints now enforced at database level
- Changed
PermissionRegistrar::initializeCache()from private to public - Collections changed from
Support\CollectiontoEloquent\Collection
Database Changes
Unique constraints are now enforced at the database level. Create a migration to add these constraints:Upgrading from v2 to v3
- PHP 7.2+ required
- Laravel 5.8+ required
- No other breaking changes
Upgrading from v1 to v2
V2 introduced a complete restructure of the database schema and code architecture.Manual Migration Required
You’ll need to:- Manually migrate your data to the new structure
- Update all code to use new methods
- Remove old
laravel-permission.phpconfig - Publish and configure new
permission.phpconfig
Getting Help
If you encounter issues during upgrade:- Review the complete Changelog
- Check GitHub Issues
- Consult the Release Notes
- See the Troubleshooting guide
Always test upgrades in a development environment before deploying to production.