How can I define a route differently if parameter is not integer

后端 未结 4 1347
无人及你
无人及你 2021-01-17 08:08

I am using Laravel 5 and working on my local. I made a route with a parameter of {id} and another route with a specific name like so :

Route::get(\'contacts/         


        
4条回答
  •  礼貌的吻别
    2021-01-17 09:04

    There is also the possibility to just switch those around, because route file will go through all lines from top to bottom until it finds a valid route.

    Route::get('contacts/new', 'ContactController@new_contact');
    Route::get('contacts/{id}', 'ContactController@get_contact');
    

    If you want to restrict that route to pure numbers, the marked solution is correct though.

    Just adding it here, I know it is quite old ;)

提交回复
热议问题