Silber\Bouncer\Clipboard::getRoles PHP Method

getRoles() public method

Get the given authority's roles.
public getRoles ( Model $authority ) : Collection
$authority Illuminate\Database\Eloquent\Model
return Illuminate\Support\Collection
    public function getRoles(Model $authority)
    {
        $collection = $authority->roles()->get(['name'])->pluck('name');
        // In Laravel 5.1, "pluck" returns an Eloquent collection,
        // so we call "toBase" on it. In 5.2, "pluck" returns a
        // base instance, so there is no "toBase" available.
        if (method_exists($collection, 'toBase')) {
            $collection = $collection->toBase();
        }
        return $collection;
    }

Usage Example

Example #1
0
 /**
  * Get the given user's roles.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $user
  * @return \Illuminate\Support\Collection
  */
 public function getRoles(Model $user)
 {
     $key = $this->tag . '-roles-' . $user->getKey();
     return $this->cache->sear($key, function () use($user) {
         return parent::getRoles($user);
     });
 }
All Usage Examples Of Silber\Bouncer\Clipboard::getRoles