Example #1
0
 /**
  * {@inheritdoc}
  */
 public function __construct(WP $wp, Request $request)
 {
     parent::__construct($wp, $request);
     $query = $this->wp->posts($this->postType);
     if ($order = $this->route('order')) {
         call_user_func_array([$query, 'orderBy'], $order);
     } else {
         $query->orderBy('created_at', 'desc');
     }
     if ($this->term = $this->getTerm()) {
         $query->whereTerm($this->term);
     }
     if ($this->date = $this->getDate()) {
         $query->whereDate('created_at', $this->date);
     }
     $this->posts = $query->paginate($this->route('limit') ?: 10);
     $this->page = $this->posts->currentPage();
     if ($this->posts->isEmpty() && $this->page > 1) {
         throw new NotFoundHttpException();
     }
 }