Tutorial by Examples

Routing defines a map between HTTP methods and URIs on one side, and actions on the other. Routes are normally written in the app/Http/routes.php file. In its simplest form, a route is defined by calling the corresponding HTTP method on the Route facade, passing as parameters a string that match...
Named routes are used to generate a URL or redirects to a specific route. The advantage of using a named route is, if we change the URI of a route in future, we wouldn't need to change the URL or redirects pointing to that route if we are using a named route. But if the links were generated using ...
You can use route parameters to get the part of the URI segment. You can define a optional or required route parameter/s while creating a route. Optional parameters have a ? appended at the end of the parameter name. This name is enclosed in a curly braces {} Optional Parameter Route::get('profi...
If you want to catch all routes, then you could use a regular expression as shown: Route::any('{catchall}', 'CatchAllController@handle')->where('catchall', '.*'); Important: If you have other routes and you don't want for the catch-all to interfere, you should put it in the end. For example: ...
This is a common gotcha with Laravel routes. Routes are matched in the order that they are declared. The first matching route is the one that is used. This example will work as expected: Route::get('/posts/{postId}/comments/{commentId}', 'CommentController@show'); Route::get('/posts/{postId}', 'P...
Routes in Laravel are case-sensitive. It means that a route like Route::get('login', ...); will match a GET request to /login but will not match a GET request to /Login. In order to make your routes case-insensitive, you need to create a new validator class that will match requested URLs agains...

Page 1 of 1