entrust
entrust copied to clipboard
Duplicate query Roles
Fix, please duplicate query Roles in EntrustUserTrait
protected $roles;
//Big block of caching functionality.
public function cachedRoles() {
if ($this->roles instanceof Collection)
return $this->roles;
$userPrimaryKey = $this->primaryKey;
$cacheKey = 'entrust_roles_for_user_' . $this->$userPrimaryKey;
if (Cache::getStore() instanceof TaggableStore) {
return $this->roles = Cache::tags(Config::get('entrust.role_user_table'))->remember($cacheKey, Config::get('cache.ttl'), function () {
return $this->roles()->get();
});
} else
return $this->roles = $this->roles()->get();
}
Add to file EntrustUserTrait and EntrustRoleTrait
use Illuminate\Database\Eloquent\Collection;
and for EntrustRoleTrait
protected $perms;
//Big block of caching functionality.
public function cachedPermissions()
{
if ($this->perms instanceof Collection) {
return $this->perms;
}
$rolePrimaryKey = $this->primaryKey;
$cacheKey = 'entrust_permissions_for_role_' . $this->$rolePrimaryKey;
if (Cache::getStore() instanceof TaggableStore) {
// return Cache::store('array')->tags(Config::get('entrust.permission_role_table'))->remember($cacheKey, Config::get('entrust.cache.ttl', 60), function () {
return Cache::tags(Config::get('entrust.permission_role_table'))->remember($cacheKey, Config::get('entrust.cache_ttl', 60), function () {
return $this->perms()->get();
});
} else {
return $this->perms = $this->perms()->get();
}
}
set:
CACHE_DRIVER=array
in .env file
and add 'ttl' in confg/cache.php
return [
/***/
'ttl' => 60,
/***/
];
@karnasoneji wrong place.
Don't forget to clear cache config.
thanks @tatarysh 👍