daylerees/docs-reader — pull request #7 by j20 (2013-02-07 20:48:57+00:00)
Title: Updated docs/routing.md to fix the Optional Routing Parameters example

Is this the proper place to contribute revisions to Laravel 4's beta docs? (The laravel/framework repo doesn't contain any docs for me to edit.)

This is a minor fix to get one example 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