ATIKON ATIKON - 1 year ago 69
PHP Question

Route with parameter laravel 5.2

I was descriped routes.php as

Route::get('/{id}', 'HomeController@index');

And I want to use HomeController without parameter too. How to do it?

if url without parameter, I also want to use HomeController to display homepage, if url with parameter I want to display some data using controller.

Answer Source

You want to use optional parameters:

Route::get('/{id?}', 'HomeController@index');

Occasionally you may need to specify a route parameter, but make the presence of that route parameter optional. You may do so by placing a ? mark after the parameter name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download