Skip to content

Commit

Permalink
Refactor(Cleanup): Remove function that was commented out
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Koenders committed Feb 2, 2017
1 parent cdda621 commit fac7dd7
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/Entrust/Traits/EntrustRoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,42 @@ trait EntrustRoleTrait
public function cachedPermissions()
{
$rolePrimaryKey = $this->primaryKey;
$cacheKey = 'entrust_permissions_for_role_'.$this->$rolePrimaryKey;
if(Cache::getStore() instanceof TaggableStore) {
$cacheKey = 'entrust_permissions_for_role_' . $this->$rolePrimaryKey;
if (Cache::getStore() instanceof TaggableStore) {
return Cache::tags(Config::get('entrust.permission_role_table'))->remember($cacheKey, Config::get('cache.ttl', 60), function () {
return $this->perms()->get();
});
}
else return $this->perms()->get();
} else return $this->perms()->get();
}

public function save(array $options = [])
{ //both inserts and updates
if(!parent::save($options)){
if (!parent::save($options)) {
return false;
}
if(Cache::getStore() instanceof TaggableStore) {
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)){
if (!parent::delete($options)) {
return false;
}
if(Cache::getStore() instanceof TaggableStore) {
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()){
if (!parent::restore()) {
return false;
}
if(Cache::getStore() instanceof TaggableStore) {
if (Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.permission_role_table'))->flush();
}
return true;
Expand All @@ -64,8 +66,7 @@ public function restore()
*/
public function users()
{
return $this->belongsToMany(Config::get('auth.providers.users.model'), Config::get('entrust.role_user_table'),Config::get('entrust.role_foreign_key'),Config::get('entrust.user_foreign_key'));
// return $this->belongsToMany(Config::get('auth.model'), Config::get('entrust.role_user_table'));
return $this->belongsToMany(Config::get('auth.providers.users.model'), Config::get('entrust.role_user_table'), Config::get('entrust.role_foreign_key'), Config::get('entrust.user_foreign_key'));
}

/**
Expand All @@ -90,7 +91,7 @@ public static function boot()
{
parent::boot();

static::deleting(function($role) {
static::deleting(function ($role) {
if (!method_exists(Config::get('entrust.role'), 'bootSoftDeletes')) {
$role->users()->sync([]);
$role->perms()->sync([]);
Expand All @@ -103,8 +104,8 @@ public static function boot()
/**
* Checks if the role has a permission by its name.
*
* @param string|array $name Permission name or array of permission names.
* @param bool $requireAll All permissions in the array are required.
* @param string|array $name Permission name or array of permission names.
* @param bool $requireAll All permissions in the array are required.
*
* @return bool
*/
Expand Down Expand Up @@ -151,9 +152,9 @@ public function savePermissions($inputPermissions)
$this->perms()->detach();
}

if(Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.permission_role_table'))->flush();
}
if (Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.permission_role_table'))->flush();
}
}

/**
Expand Down

0 comments on commit fac7dd7

Please sign in to comment.