laravel/docs — pull request #134 by j20 (2013-02-08 03:52:02+00:00)
Title: Updated docs/routing.md to fix the Optional Routing Parameters example

This is a minor fix to get one of the examples working.

For a route with an optional parameter, all three of the following URLs should work (url, url/, url/param). But with the current example: user and user/ both return an error ("whoops, missing argument 1 for {closure}()"). For this optional routing parameter example to work for all three urls (url, url/, and url/param), it seems the parameter needs to default to null, to prevent errors when the optional parameter is not used.

// An example
Route::get('user/{name?}', function($name = null)
{
return 'This string is always shown. But the name is optional: '.$name;
});

This will work without an error for: user, user/ and user/john