/** * Create paginator * * @param Illuminate\Support\Collection $collection * @param int $total * @param int $perPage * @return string */ public static function makeLengthAware($collection, $total, $perPage) { $paginator = new LengthAwarePaginator($collection, $total, $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]); return str_replace('/?', '?', $paginator->render()); }
/** * paginate to create my table * * * @param $table * @param $table_name * @return string */ protected function paginate($table, $table_name) { $paginate = new LengthAwarePaginator($table, count($table), $this->row_per_page, $this->current_page); $total_rows = count($table); // we should select only posts that we want; $table = array_slice($table, $this->current_page * $this->row_per_page - $this->row_per_page, $this->row_per_page); $start_id = $this->current_page * $this->row_per_page - $this->row_per_page; $start_id++; $end_id = $this->current_page * $this->row_per_page; if ($end_id > $total_rows) { $end_id = $total_rows; } if ($total_rows == 0) { $start_id = 0; } if ($end_id < $this->row_per_page) { $this->row_per_page = $end_id; } $footer_info = "<div style='margin-top:17px;float:left;' class='footer-data-table-info'>نمایش <b>" . $start_id . "</b> تا <b>" . $end_id . "</b> ، <b>" . $this->row_per_page . "</b> سطر در هر صفحه ، کل سطرها <b>{$total_rows}</b></div>"; return json_encode([$table_name => $table, "paginate" => $paginate->render(), "page_id" => $this->current_page, "row_per_page" => $this->row_per_page, "start_id" => $start_id, "footer_info" => $footer_info, "random" => $this->random_number]); }
public function render($class = null) { return $this->paginator->render(static::$defaultView); }
public function respondWithPaginated(LengthAwarePaginator $paginated, $status = 200) { $this->options['paginationCode'] = $paginated->render(); $this->prepareEloquentResult($paginated); return $this->respond(collect($paginated), $status); }