How can I change this URL generated from submitting the form-
http://localhost:8000/estates?zone=London&type=villa
to this URL:
http://localhost:8000/estates/London/villa
Need to make the URL more friendly for search engines.
I get the zone and villa from input fields in a form in
localhost:8000/estates
When I submit the form I get a URL like this-
localhost:8000/estates?zone=London&type=villa
Instead of above I would like to have this URL when I submit the form-
localhost:8000/estates/London/villa
2
Answers
You should restructure your routes so zone and village become route parameters.
So, for example, the route for http://localhost:8000/estates/London/villa would be
Route::post('/estates/{zone}/{villa}', 'SomeController@action')
and in the controller you can inject the zone and village as parameters. So you can use something like this :It is described further in the Route parameters section of Routing in Laravel docs.
When you submit the form, it should catch the post data in controller action like this-
As you can see you have received the input field in request in your store method, now you can do something like this-
Please make sure you have the routes created for zone and villa otherwise redirecting to a non-existing route/url will not work.
Create a route like this for your request-
You will have another action method in your controller to receive this zone and villa inputs like this-