/** * Create a privilege for the authorable as $role on $resource. * * @param Agency\Cms\Auth\Authorization\Entities\Role $role * @param mixed $resource Can be any reference to the resource or the resource itself. * @param array $attributes * @return Agency\Cms\Auth\Authorization\Entities\Privilege */ protected function createPrivilege(Role $role, $resource, $attributes = [], $for_artists) { $section = 'section'; return Privilege::createWith($attributes, ['admin' => $this->authorable->getKey(), 'role' => $role, $section => $resource]); }
/** * Get all the privileges of a given authorable. * * @param Agency\Contracts\Cms\AuthorableInterface $authorable * @return Illuminate\Database\Eloquent\Collection */ protected function all(AuthorableInterface $authorable) { return Privilege::with($this->with)->whereHas('admin', function ($q) use($authorable) { $q->where('id', $authorable->getKey()); })->get(); }
public function __construct(AuthorableInterface $authorable, $resources) { $resource_types = $this->extractResourceTypes($resources); $previous = Privilege::where('admin_id', $authorable->getKey())->whereIn('resource_type', $resource_types)->delete(); }