Pagination for search results laravel 5.3

前端 未结 10 1381
无人及你
无人及你 2021-02-01 06:17

Pagination search results

I have just started with Laravel and I am trying to make a search function with proper pagination. The function works for page one but on pag

10条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 07:05

    in my case, i've laravel 5.7 installed.

    $perPage = $request->per_page ?? 10;
    
    $data['items'] = User::where('name', 'like', '%'. $request->search . '%')
                             ->paginate($perPage)
                             ->appends(['search' => $request->search, 'per_page' => $request->per_page]);
    
        return view('users.index', $data);
    

    and my view files codes are

    for per_page select dropdown and search area

    and my pagination generator code

    {{ $items->appends(['search' => request()->search, 'per_page' => request()->per_page])->links() }}
    

提交回复
热议问题