Silber\Bouncer\CachedClipboard::getAbilities PHP Метод

getAbilities() публичный Метод

Get the given authority's abilities.
public getAbilities ( Model $authority, boolean $allowed = true ) : Illuminate\Database\Eloquent\Collection
$authority Illuminate\Database\Eloquent\Model
$allowed boolean
Результат Illuminate\Database\Eloquent\Collection
    public function getAbilities(Model $authority, $allowed = true)
    {
        $key = $this->getCacheKey($authority, 'abilities', $allowed);
        if (is_array($abilities = $this->cache->get($key))) {
            return $this->deserializeAbilities($abilities);
        }
        $abilities = $this->getFreshAbilities($authority, $allowed);
        $this->cache->forever($key, $this->serializeAbilities($abilities));
        return $abilities;
    }

Usage Example

Пример #1
0
 /**
  * Get the user's abilities from the given cache instance through the clipboard.
  *
  * @param  \Illuminate\Cache\ArrayStore  $cache
  * @param  \Illuminate\Database\Eloquent\Model  $user
  * @return array
  */
 protected function getAbliities(ArrayStore $cache, Model $user)
 {
     $clipboard = new CachedClipboard($cache);
     $abilities = $clipboard->getAbilities($user)->lists('name');
     return $abilities->sort()->values()->all();
 }