Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions src/Entrust/Traits/EntrustRoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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([]);
Expand Down
31 changes: 10 additions & 21 deletions src/Entrust/Traits/EntrustUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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([]);
Expand Down