Pagination for search results laravel 5.3

前端 未结 10 1370
无人及你
无人及你 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 06:43

    a quick way in view (Lavarel 5.7)

    $product->appends(Request::all())->links();
    
    0 讨论(0)
  • 2021-02-01 06:47
    Route::get('product', function () {
        $product= App\product::paginate(15);
    
        $product->setPath('custom/url');
    
    });
    

    View:

    {{ $product->appends(['search' => Request::get('page')])->links() }}
    
    0 讨论(0)
  • 2021-02-01 06:47

    In your view file where you display pagination...

    {{ $results->appends(Request::except('page'))->links() }}
    

    appends keeps the query string value except "page".

    0 讨论(0)
  • 2021-02-01 06:48

    If you are using search form with GET method then use something like these to preserve pagination withing search results.

     public function filter(Request $request)
        {        
            $filter = $request->only('name_operator','name_value','email_operator','email_value', 'phone_operator','phone_value',   'gender_value', 'age_operator','age_value');
            $contacts = $this->repo->getFilteredList(array_filter($filter));
            $contacts->appends($filter)->links(); //Continue pagination with results
            return view('dashboard::index', compact('contacts'))->withInput($request->all());
        }
    
    0 讨论(0)
  • 2021-02-01 06:50
    $searchdata =  \Request::get( 'inputTextFieldname' ); \make as global
    $searchresult = Modelname::where ( 'blogpost_title', 'LIKE', '%' .$searchdata . '%' )->paginate(2);
    return view( 'search', compact('searchresult') );
    

    and in your view page

    {{$searchresult->appends(Request::only('inputTextFieldname'))->links()}}
    

    make your route to get method

    Route::get('/search', ['as' => 'search', 'uses' => 'searchController@index']);
    

    this will be done, thanks,

    0 讨论(0)
  • 2021-02-01 06:51

    use any in route Instead post Route::any('search', 'IndexController@search');

    0 讨论(0)
提交回复
热议问题