0

I have this form and I want to add a controller that receives the search query from the search form and echo it on the screen.

dashboard.blade file

 <form action="{{ route('Q') }}" method="POST">
    @csrf
    <input type="text" name="query">

    <button type="submit"> search </button>
</form>

controller code :

class ProductsController extends Controller
{
    
    public function retrieveProducts(Request $request)
{
    $product = $request->input('query');
    dd($request->all());
}


}


I used this two routes :

Route::get('/', function () {
    return view('dashboard');
});


Route::post('/', [ProductsController::class, 'retrieveProducts'])->name('Q');

The result : result. expected result : expected result

  • Can you be more specific? Nothing is displayed, do you have an error message? Can you also try in your controller to add `dd($request->all())` at the top of the action and edit your question with the result please? – Jedupont May 11 '22 at 15:40
  • @Jedupont done, I added the result and the expected result at the end to make it clear. – Hussein M Malkawi May 11 '22 at 16:08
  • You are not being clear. You want the search query shown on the blade view? You can use `{{request()->query}}` – Snapey May 11 '22 at 22:26

0 Answers0