一、我們查詢的時候使用的 paginate 方法,該分頁函數在以下位置
項目根目錄\vendor\laravel\framework\src\Illuminate\Database\Eloquent 下 Builder.php文件
模板中調用 render()方法在 LengthAwarePaginator.php文件中
項目根目錄\vendor\laravel\framework\src\Illuminate\Pagination
這裏採用的模板是 static::$defaultView
在AbstractPaginator.php文件中
項目根目錄\vendor\laravel\framework\src\Illuminate\Pagination
分頁模板位置在 default.blade.php文件, 位置如下
項目根目錄\resources\views\vendor\pagination
二、如果需要創建一個分頁模板,可在
- AbstractPaginator.php 文件增加
public static $homePageView = "pagination::home-page";
名稱可自定義 - LengthAwarePaginator.php 文件增加
public function homeRender($view = null, $data = []){
return new HtmlString(static::viewFactory()->make($view ?: static::$homePageView, array_merge($data, [
'paginator' => $this,
'elements' => $this->elements(),
]))->render());
}
3.Builder.php文件增加
public function homePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null){
$page = $page ?: Paginator::resolveCurrentPage($pageName);
$perPage = $perPage ?: $this->model->getPerPage();
$results = ($total = $this->toBase()->getCountForPagination())
? $this->forPage($page, $perPage)->get($columns)
: $this->model->newCollection();
return $this->Paginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
}
4.數據查詢使用 homePaginate()方法
5.前臺模板調用爲 homeRender();
6.分頁模板創建
淘寶優惠券領取 http://tao.paetao.com