# Upgrade from 4.0 to 5.0
IMPORTANT
Laratrust 5.0 requires Laravel >= 5.2.32.
In order to upgrade from Laratrust 4.0 to 5.0 you have to follow these steps:
- Change your
composer.json
to require the 5.0 version of Laratrust:
"santigarcor/laratrust": "5.0.*"
Run
composer update
to update the source code.Run
php artisan config:clear
andphp artisan cache:clear
.Update your
config/laratrust.php
:4.1. Backup your
config/laratrust.php
configuration values.4.2. Delete the
config/laratrust.php
file.4.3. Run
php artisan vendor:publish --tag=laratrust
.4.4. Update the
config/laratrust.php
file with your old values.4.5. Set the
middleware.register
value tofalse
.4.6. Set the
teams_strict_check
value totrue
only if you are using teams.Inside your
Role
,Permission
andTeam
models update theuse
statement from:use Laratrust\LaratrustRole
touse Laratrust\Models\LaratrustRole
;use Laratrust\LaratrustPermission
touse Laratrust\Models\LaratrustPermission
;use Laratrust\LaratrustTeam
touse Laratrust\Models\LaratrustTeam
;
If you use the ability method and you pass it comma separated roles or permissions, change them to a pipe separated string:
// From
$user->ability('admin,owner', 'create-post,edit-user');
// To
$user->ability('admin|owner', 'create-post|edit-user');
- If you are using the
Ownable
interface, please update all the classes implementing it:
// From
public function ownerKey() {}
// To
public function ownerKey($owner) {}
If you use teams and in your code you use the
syncRoles
andsyncPermissions
read the new sync method behavior.The
cachedRoles
andcachedPermissions
methods now return an array when you have thelaratrust.use_cache
option set totrue
. So if you use these methods, please check your code.Delete the
LaratrustSeeder.php
file and runphp artisan laratrust:seeder
.Run
composer dump-autoload
.
Now you can use the 5.0 version without any problem.