Example #1
0
 /**
  * @param        $title
  * @param        $route
  * @param        $controller
  * @param        $layout
  * @param string $section
  * @param string $method
  * @param null   $alias
  * @return Page
  */
 public static function createWithContent($title, $route, $controller, $layout = 'layouts.default', $method = 'get', $alias = null)
 {
     $page = Page::whereRoute($route)->whereMethod($method)->first();
     // Nothing to do if the page already exists
     if ($page) {
         return $page;
     }
     // Page does not exist yet, continue creating...
     if (!$alias) {
         $alias = $route;
     }
     $page = new Page();
     $page->title = $title;
     $page->route = $route;
     $page->alias = $alias;
     $page->controller = $controller;
     $page->method = $method;
     if ($layout) {
         $layout = Layout::whereName($layout)->first();
         $page->layout()->associate($layout);
     }
     $page->save();
     Event::fire('page.createWithContent', array($page));
     // Dynamically add the Laravel route
     self::createRoute($page);
     return $page;
 }
Example #2
0
 /**
  * @param        $title
  * @param        $route
  * @param        $controller
  * @param string $method
  * @param string $layout
  * @param string $section
  * @param array  $params
  * @param array  $match
  *
  * @return \Boyhagemann\Pages\Model\Page
  */
 public static function createWithContent($title, $route, $controller, $method = 'get', $layout = 'layouts.default', $section = 'content', $params = null, $match = null)
 {
     $layout = Layout::whereName($layout)->first();
     $section = Section::whereName($section)->first();
     $page = new Page();
     $page->title = $title;
     $page->route = $route;
     $page->layout()->associate($layout);
     $page->method = $method;
     $page->save();
     $content = new Content();
     $content->page()->associate($page);
     $content->section()->associate($section);
     $content->controller = $controller;
     $content->params = (array) $params;
     $content->match = (array) $match;
     $content->save();
     return $page;
 }