0
votes

I am trying to do search with pagination but I am stuck with this GET error.

function search_document(Request $request){
    $result = Document::where("title","like", "%".$request->input('query')."%")->paginate(5);
    return view('/admin/documents')->with(["documents"=>$result]);
}

Error I got

  1. URL changed to /api/search_document that has to be like /admin/documents
  2. I am getting this Error

enter image description here

Route is like this :

Route::post("search_document",[adminDocumentController::class, 'search_document']);

Blade File Code

<form action="/api/search_document" class="main__title-form" method="POST">
                        <input type="text" placeholder="Find document" name="query">
                        <button type="submit">
                            <i class="icon ion-ios-search"></i>
                        </button>
                    </form>

Please help me

1
Change your route Route::post… to Route::get…sta
Then How I will pass query data to the Route?Pooja
I am using a Form to perform Search ActionPooja
Can you post your form code with your questionsta
You can simply change method="POST" to method="GET" and also from route. By default laravel pagination uses the get parametersta

1 Answers

1
votes

Change your route from post to get, then in your controller method will receive request as parameter, your form method should also be GET,

check this material out How to implement search functionality in laravel 8