Skip to content
Advertisement

Laravel 7 – Redirects to the main page when the optional parameter is empty

I have a route with an optional parameter in web.php:
my web.php: (the route that has the problem is marked with a comment)

JavaScript

and it is my dashboard middleware:

JavaScript

When I enter the host-name/drivers/driver-dropdown/jo URL, I get jo
BUT When I enter the host-name/drivers/driver-dropdown/ URL, I will be redirected to the host-name/ that means root route!

Edit: updated web.php

Advertisement

Answer

You should reorder your routes like this:

JavaScript

Currently, when you go to host-name/drivers/driver-dropdown/, it will match the /{id} route.

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