Or you can use an Artisan command: php artisan permission:cache-reset To manually reset the cache for this package, you can run the following in your app code: app () -> make ( \Spatie\Permission\PermissionRegistrar ::class ) -> forgetCachedPermissions () $user -> assignRole ( 'writer' ) $user -> removeRole ( 'writer' ) $user -> syncRoles ( params ) #Manual cache reset NOTE: User-specific role/permission assignments are kept in-memory since v4.4.0, so the cache-reset is no longer called since v5.1.0 when updating User-related assignments.Įxamples: // These do not call a cache-reset, because the User-related assignments are in-memory. If you have created your own models which do not extend the default models then you will need to implement the trait yourself. HOWEVER, if you manipulate permission/role data directly in the database instead of calling the supplied methods, then you will not see the changes reflected in the application unless you manually reset the cache.Īdditionally, because the Role and Permission models are Eloquent models which implement the RefreshesPermissionCache trait, creating and deleting Roles and Permissions will automatically clear the cache. When you use the built-in functions for manipulating roles and permissions, the cache is automatically reset for you, and relations are automatically reloaded for the current model record: $role -> givePermissionTo ( 'edit articles' ) $role -> revokePermissionTo ( 'edit articles' ) $role -> syncPermissions ( params ) $permission -> assignRole ( 'writer' ) $permission -> removeRole ( 'writer' ) $permission -> syncRoles ( params ) #Automatic Cache Refresh Using Built-In Functions Role and Permission data are cached to speed up performance.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |