My problem is that I want to paginate the search results, but laravel's paging is based on Elouqent and the database query builder. I don't know how to implement it in the controller and front-end view.
This is the code to do a database search:
$article = Searchy::companys('title','body')->query($request->seek)->get();
Please give me some advice.
ringa_lee2017-05-16 16:53:28
public function all(Request $request)
{
$user = User::latest()->get();
foreach ( $user as $key=>$value){
$company = Company::find($value->company_id);
$title = CompanyTitle::find($value->title_id);
$value['titleName'] = $title->title;
$value['companyName'] = $company->name;
}
$size = 8;
if (empty($request->page)){
$page = 1;
}
else{
$page = $request->page;
}
$users = $user->toArray();
$item = array_slice($users, ($page - 1) * $size,$size);
$arr =new LengthAwarePaginator($item, count($user), $size, $page, [
'path' => Paginator::resolveCurrentPath(), //注释2
'pageName' => 'page',
]);
return $arr;
}
This is a blog I read myself, which solved the problem of no instantiation and no link. When writing code, the page number was not processed, which is not good code. . .
Blog address Laravel manual paging implementation
曾经蜡笔没有小新2017-05-16 16:53:28
Use Illuminatepagniate or lengthawaredpagniate.
Then for new Paginate(), you need to check the incoming parameters in the manual