I use a third-party search package in Laravel, but I don't know how to paginate the search results?
伊谢尔伦
伊谢尔伦 2017-05-16 16:51:28
0
3
450

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.

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all (3)
左手右手慢动作
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

    曾经蜡笔没有小新

    Use Illuminatepagniate or lengthawaredpagniate.

    Then for new Paginate(), you need to check the incoming parameters in the manual

      为情所困

      You don’t need to get, just use pagination directly after the query

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!