Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davidSoto's avatar

Optional parameters

Hello, I have this route

Route::get('/proyectos/{nombre?}/{users?}/{sortField?}/{dir?}', 'ProyectoController@index');

and its controller:

public function index($nombre='',  $users='',  $sortField='',  $dir='') 

my question is, if I don't send one parameter for example 'sortField', what is the url sintax?

If I send proyectos/nombre/user/dir the url dir value is assigned to sortField in controller

If I send proyectos/nombre/user//dir I have an error 404 (page not found)

and the url query string is not processed by laravel 5

any idea?

0 likes
1 reply
shez1983's avatar

in this case i think it would be better if you send 0 or something and then check for that in your code.. i dont think you can ommit it like you have done - you can ommit the last one dir? i am positive but not any of the previous ones..

i am not sure what dir? is but sortfield looks like a FILTER to sort by something.. usually people use ? GET params to do that ie ?filter=name... etc

1 like

Please or to participate in this conversation.