Full Text Search in Laravel 5 Example - how to add pagination to the results

Posted in CategoryLaravel
  • J
    Jaro13 7 months ago

    Thanks for a great tutorial:

    http://itsolutionstuff.com/post/full-text-search-in-laravel-5-exampleexample.html

    Is it possible to add paginations to the search results? I know there are some issues with "nicolaslopezj/searchable".  How can we fix it?

    Thanks again!

     

  • H
    Hardik Savani 7 months ago

    If you follow this tutorial: https://itsolutionstuff.com/post/full-text-search-in-laravel-5-exampleexample.html Then i think you can make pagination as now laravel, like as below:

     

     

    public function mySearch(Request $request)

    {

    if($request->has('search')){

    $users = User::search($request->get('search'))->paginate(10);

    }else{

    $users = User::paginate(10);

    }

     

    return view('my-search', compact('users'));

    }

  • J
    Jaro13 7 months ago

    Thank You! It works! You are genius! I had a problem with:

     

    else{

    $users = User::paginate(10); //we have to add paginate function here too!

    }

     

     

    I have another question: Is it possible to combine full-text search in Laravel with bootstrap3 typeahead (as shown in article https://itsolutionstuff.com/post/laravel-5-autocomplete-using-bootstrap-typeahead-js-example-with-demoexample.html). Do You have any ideas how to implement it? Thanks for your generosity in sharing your valuable knowledge!

     

  • H
    Hardik Savani 7 months ago

    Yes sure you can implement it. You have to just change here:

    $data = Item::select("title as name")

            ->where("title","LIKE","%{$request->input('query')}%")

            ->get();

    INTO

    $data = Item::select("title as name")

            ->search($request->input('query'))

            ->get();

     

  • J
    Jaro13 7 months ago

    Thanks! It works! Simple and effective solution!

     

    I've noticed one problem with function:

     

    public function mySearch(Request $request)

    {

    if($request->has('search')){

    $users = User::search($request->get('search'))->paginate(10);

    }else{

    $users = User::paginate(10);

    }

     return view('my-search', compact('users'));

    }

     

    if we find through search function some records (it's easy to notice if we change pagination to value 1) and for example, we've got 2 pages of results, and we choose the second page, ALL PAGES APPEAR but we should be able to move only within 2 pages which contain our search results. How to fix it?

     

     

     

  • F
    Fharza 7 months ago

    Thanks for a great tutorial, i have problem how to set search in select opntion by category and search in input by name,  ? 

     

Please login or register to leave a response.

* You May Also Like Bellow Issue to check *