Exemplo n.º 1
0
 /**
  * Calculate the pagination variables
  */
 private function calculatePagination()
 {
     // Count the number of posts with this tag
     $this->totalPosts = ProductsProduct::whereHas('tags', function ($tag) {
         $tag->where('name', $this->property('tag'));
     })->count();
     // Calculate the results per page
     $this->resultsPerPage = $this->property('pagination') ? intval($this->property('resultsPerPage')) : $this->totalPosts;
     // Calculate the last page
     $this->lastPage = ceil($this->totalPosts / $this->resultsPerPage);
     // Prevent the current page from being one that doesn't exist
     if ($this->currentPage < 1) {
         $this->currentPage = 1;
     }
     if ($this->currentPage > $this->lastPage) {
         $this->currentPage = $this->lastPage;
     }
     // Calculate the previous page
     $this->previousPage = $this->currentPage > 1 ? $this->currentPage - 1 : false;
     // Calculate the next page
     $this->nextPage = $this->currentPage < $this->lastPage ? $this->currentPage + 1 : false;
 }