예제 #1
0
파일: Access.php 프로젝트: adibhanna/agency
 /**
  * Create a new Access instance.
  *
  * @todo  Implement sending all privileges of an admin when no resources specified
  *
  * @param Agency\Cms\Authority\Contracts\AuthorableInterface $authorable
  * @param array $resources
  */
 public function __construct(AuthorableInterface $authorable, Collection $resources)
 {
     $query = Privilege::with('role')->orderBy('resource_id');
     foreach ($resources as $resource) {
         if (!$resource instanceof PrivilegableInterface) {
             throw new InvalidResourceTypeException('must implement PrivilegableInterface');
         }
         $query->orWhere(function ($q) use($authorable, $resource) {
             $q->where('admin_id', $authorable->identifier());
             $q->where('resource_id', $resource->identifier());
             $q->where('resource_type', get_class($resource));
         });
     }
     $privileges = $query->get();
     // dd(\DB::getQueryLog());
     $this->accessible['resources'] = $this->getAccessibleResources($privileges);
 }