public function discover() { $resource = new Resource(); $resource->addLink(RestLinker::createLinkToFirstPage('users')); // viewing the list of roles should be only allowed for admins if ($this->authorizationService->hasRoles(['ADMIN'])) { $resource->addLink(RestLinker::createLink('roles')); } // etc... return RestResponse::sendResource($resource); }
/** * Creates a Response object filled with the content and meta info of the Resource which is returned * * @param \Noherczeg\RestExt\Http\Resource $fromResource * @return \Illuminate\Http\Response */ public function sendResource(Resource $fromResource) { $finalizedResource = $fromResource->getLinks() === null && $fromResource->getPagesMeta() === null ? $fromResource->getContent() : $fromResource; $response = $this->embededResponse->create($this->createResponseBody($finalizedResource), $this->createResponseCode()); $response->setCharset($this->config->get('restext::encoding')); $response->headers->set('Content-Type', $this->createContentType($this->config->get('restext::media_type'), $this->config->get('restext::encoding'))); return $response; }
/** * Adds multiple Links to the Resource under generation. * * @param array $links * @return RestExt */ public function addLinks(array $links) { $this->resource->addLinks($links); return $this; }