public function update(Page $page, Request $request)
 {
     $rules = $this->rules;
     $rules['slug'] .= ',' . $page->id;
     $this->validate($request, $rules);
     $page->update($request->all());
     return redirect()->route('dashboard.page.show', $page);
 }
 /**
  * Register bindings in the container.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('frontend.layout', function ($view) {
         $contentPages = Cache::remember('contentPages', 10, function () {
             return Page::sorted()->whereNull('parent_id')->with(['childs.pageable', 'childs.parent', 'pageable'])->get();
         });
         $view->with('contentPages', $contentPages);
     });
 }
 /**
  * Register any other events for your application.
  *
  * @param  \Illuminate\Contracts\Events\Dispatcher  $events
  * @return void
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     Collection::created(function ($collection) {
         /** @var Collection $collection */
         $page = new Page();
         $page->title = $collection->title;
         $collection->page()->save($page);
     });
     Poem::created(function ($poem) {
         /** @var Poem $poem */
         $page = new Page();
         $page->title = $poem->title;
         /** @var Collection $collection */
         $collection = $poem->collection;
         $parentPage = $collection->page;
         $page->parent()->associate($parentPage);
         $poem->page()->save($page);
     });
 }
 /**
  * @param Page $pagerCurrentPage
  * @return IlluminateCollection
  */
 protected function getPager($pagerCurrentPage)
 {
     $pagerCurrentPage = $pagerCurrentPage->id ? $pagerCurrentPage : Page::sorted()->visible()->first();
     $pager = new IlluminateCollection();
     $pager->push($pagerCurrentPage);
     // e.g. page 6
     /** @var Collection $previousPages */
     $previousPages = $pagerCurrentPage->previous(4)->visible()->with(['pageable', 'parent'])->get();
     // 5 4 3 2
     /** @var Collection $nextPages */
     $nextPages = $pagerCurrentPage->next(4)->visible()->with(['pageable', 'parent'])->get();
     // 7 8 9 10
     do {
         $prevPage = $previousPages->shift();
         if ($prevPage) {
             $pager->prepend($prevPage);
         }
         $nextPage = $nextPages->shift();
         if ($nextPage) {
             $pager->push($nextPage);
         }
     } while ($pager->count() < 5 && ($previousPages->count() > 0 || $nextPages->count() > 0));
     return $pager;
 }