【发布时间】:2018-10-16 06:20:13
【问题描述】:
我在 laravel 的分页上遇到了一些麻烦。已经对表格进行了分页。但在视图页面中,数字不正确。这是它的样子:
https://i.stack.imgur.com/407Oo.png
另一个问题是当我按下数字时,链接失效并给我这个错误:
Symfony\Component\HttpKernel\Exception\ MethodNotAllowedHttpException 无消息
这是我的路线:
Route::get("/", "PagesController@welcome");
Route::post("/search", "PagesController@search")->name('search.route');
这是我的观点:
public function search(Request $request)
{
$q = $request->q;
if ($q !== null && trim($q) !== ""){//here
$estates = \DB::table('allestates')
->where("building_name","LIKE", "%" . $q . "%")
->orWhere("address","LIKE", "%" . $q . "%")
->orWhere("company_name","LIKE", "%" . $q . "%")
->orWhere("region","LIKE", "%" . $q . "%")
->orderBy('price')->paginate(10);
if(count($estates) > 0){
return view("search", compact('estates'))->withQuery($q);
}
}
$estates = array();//here
return view("search", compact('estates'))->withMessage("No Found!");//here
}
另一件事是在控制器中我无法将->paginate(10) 与->get() 添加它作为错误返回,例如:
方法 Illuminate\Support\Collection::paginate 不存在。
我非常感谢任何帮助解决这个问题。谢谢! 顺便说一句,我不知道是否连接,但我已经公开删除/更改了“boostrap”文件。
【问题讨论】:
-
你可以创建一个新的 LengthAwarePaginator。一般用法如下: $new_paginate = new LengthAwarePaginator($currentItems, count($items), $perPage, $currentPage);
标签: php laravel pagination