Skip to content
Advertisement

Laravel Search Form with Filters

I want to implement a search form in Laravel, I was watched every video on YouTube to do this, and tried many tutorials but my code doesn’t work.


File web.php
In my routes are a resource with CRUD of clients, which will also have a search, which I want to implement filters, by name, by state, etc…

JavaScript

File ClientController.php
The function search is a tried to implement the search, but I know is totally wrong, but I don’t find on Google any clear tutorial I understood how to do correctly…

JavaScript

File index.blade.php
This is my page on Front-end… Has a table of all clients, and on top I want to implement a search with filters by name and by state…

JavaScript

Advertisement

Answer

You don’t have the $clients variable defined in your controller, so it would not make sense to include it in the return. Also, seeing that in your view, you loop over that variable, I think that if you simply change the name of the variable where you save the result of your query from $pesquisa to $clients, everything will work:

JavaScript

Also, your form action it’s maybe wrong, try using the route name instead the uri:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement