/** * Resolve the page. * * @return Contract\PageInterface|null */ public function resolve() { $action = $this->route->getAction(); if ($id = array_get($action, 'anomaly.module.pages::page')) { return $this->pages->find($id); } if ($path = array_get($action, 'anomaly.module.pages::path')) { return $this->pages->findByPath($path); } return null; }
/** * Redirect elsewhere. * * @param PageRepositoryInterface $pages * @param Redirector $redirector * @param Route $route * @return \Illuminate\Http\RedirectResponse|void */ public function redirect(PageRepositoryInterface $pages, Redirector $redirector, Route $route) { if ($to = array_get($route->getAction(), 'anomaly.module.pages::redirect')) { return $redirector->to($to, array_get($route->getAction(), 'status', 302)); } /* @var PageInterface $page */ if ($page = $pages->find(array_get($route->getAction(), 'anomaly.module.pages::page', 0))) { return $redirector->to($page->getPath(), array_get($route->getAction(), 'status', 302)); } abort(404); }
/** * Handle the command. * * @param PageRepositoryInterface $pages * @param ViewTemplate $template * @return PageInterface|EloquentModel|null */ public function handle(PageRepositoryInterface $pages, ViewTemplate $template) { if (is_null($this->identifier)) { $this->identifier = $template->get('page'); } if (is_numeric($this->identifier)) { return $pages->find($this->identifier); } if (is_string($this->identifier)) { return $pages->findByPath($this->identifier); } if ($this->identifier instanceof PageInterface) { return $this->identifier; } if ($this->identifier instanceof PagePresenter) { return $this->identifier->getObject(); } return null; }
/** * Delete a page and go back. * * @param PageRepositoryInterface $pages * @param Authorizer $authorizer * @param $id * @return \Illuminate\Http\RedirectResponse */ public function delete(PageRepositoryInterface $pages, Authorizer $authorizer, $id) { $authorizer->authorize('anomaly.module.pages::pages.delete'); $pages->delete($page = $pages->find($id)); $page->entry->delete(); return redirect()->back(); }