diff --git a/src/Entrust/Traits/EntrustRoleTrait.php b/src/Entrust/Traits/EntrustRoleTrait.php index 4ff0cecb..c5ed7630 100644 --- a/src/Entrust/Traits/EntrustRoleTrait.php +++ b/src/Entrust/Traits/EntrustRoleTrait.php @@ -26,36 +26,6 @@ public function cachedPermissions() } else return $this->perms()->get(); } - public function save(array $options = []) - { //both inserts and updates - if(!parent::save($options)){ - return false; - } - if(Cache::getStore() instanceof TaggableStore) { - Cache::tags(Config::get('entrust.permission_role_table'))->flush(); - } - return true; - } - public function delete(array $options = []) - { //soft or hard - if(!parent::delete($options)){ - return false; - } - if(Cache::getStore() instanceof TaggableStore) { - Cache::tags(Config::get('entrust.permission_role_table'))->flush(); - } - return true; - } - public function restore() - { //soft delete undo's - if(!parent::restore()){ - return false; - } - if(Cache::getStore() instanceof TaggableStore) { - Cache::tags(Config::get('entrust.permission_role_table'))->flush(); - } - return true; - } /** * Many-to-Many relations with the user model. @@ -90,6 +60,16 @@ public static function boot() { parent::boot(); + $flushCache = function() { + if(Cache::getStore() instanceof TaggableStore) { + Cache::tags(Config::get('entrust.permission_role_table'))->flush(); + } + }; + + static::restored($flushCache); + static::deleted($flushCache); + static::saved($flushCache); + static::deleting(function($role) { if (!method_exists(Config::get('entrust.role'), 'bootSoftDeletes')) { $role->users()->sync([]); diff --git a/src/Entrust/Traits/EntrustUserTrait.php b/src/Entrust/Traits/EntrustUserTrait.php index cd355f5e..d482ba81 100644 --- a/src/Entrust/Traits/EntrustUserTrait.php +++ b/src/Entrust/Traits/EntrustUserTrait.php @@ -27,27 +27,6 @@ public function cachedRoles() } else return $this->roles()->get(); } - public function save(array $options = []) - { //both inserts and updates - parent::save($options); - if(Cache::getStore() instanceof TaggableStore) { - Cache::tags(Config::get('entrust.role_user_table'))->flush(); - } - } - public function delete(array $options = []) - { //soft or hard - parent::delete($options); - if(Cache::getStore() instanceof TaggableStore) { - Cache::tags(Config::get('entrust.role_user_table'))->flush(); - } - } - public function restore() - { //soft delete undo's - parent::restore(); - if(Cache::getStore() instanceof TaggableStore) { - Cache::tags(Config::get('entrust.role_user_table'))->flush(); - } - } /** * Many-to-Many relations with Role. @@ -70,6 +49,16 @@ public static function boot() { parent::boot(); + $flushCache = function() { + if(Cache::getStore() instanceof TaggableStore) { + Cache::tags(Config::get('entrust.role_user_table'))->flush(); + } + }; + + static::restored($flushCache); + static::deleted($flushCache); + static::saved($flushCache); + static::deleting(function($user) { if (!method_exists(Config::get('auth.model'), 'bootSoftDeletes')) { $user->roles()->sync([]);