/**
  * updates input Page with a slug
  * @param Page $page
  */
 static function updateSlug(Page $page)
 {
     $lang = $page->getLang();
     $prefix = "";
     if ($lang != null && $lang) {
         $prefix = $lang->getCode() . "/";
     }
     $page->setSlug($prefix . Str::slug($page->getTitle()));
 }
 public function upsertPage()
 {
     $pageId = Input::get("pageid");
     if ($pageId != null && strlen(trim($pageId)) > 0) {
         $page = $this->pageRepository->find($pageId);
     }
     if (!isset($page) || $page == null) {
         $page = new Page();
     }
     $langCode = Input::get("lang");
     $lang = $this->langRepository->findByCode($langCode);
     if ($lang != null) {
         $page->setLang($lang);
     }
     $page->setSlug(trim(Input::get("pageurl")));
     $page->setContent(trim(Input::get("content")));
     $page->setTitle(Input::get("title"));
     $page->setKeywords(Input::get("keywords"));
     $page->setDomain(trim(Input::get("domain")));
     $page->setDescription(Input::get("pagedescription"));
     $page->setLayout(Layouts::byDomain($page->getDomain()));
     if ($page->getId() == null) {
         $this->pageRepository->create($page);
     } else {
         $this->pageRepository->update($page);
     }
     return \Redirect::to("/admin/site/pagini-web");
 }