Documentation Index
Fetch the complete documentation index at: https://kawax.biz/llms.txt
Use this file to discover all available pages before exploring further.
Basic routing
The most basic Laravel route accepts a URI and a closure, letting you define a route and its behavior without complex configuration files:Default route files
All Laravel routes are defined in the files inside theroutes/ directory. Laravel automatically loads these files based on the configuration in bootstrap/app.php.
Define browser-facing routes in routes/web.php. Routes in this file have the web middleware group applied, which provides session handling, CSRF protection, and cookie encryption:
Available HTTP methods
The router can register routes that respond to any HTTP verb:match or any:
HTML forms in the
web routes file that send POST, PUT, PATCH, or DELETE requests must include the @csrf Blade directive. Requests without it will be rejected.Returning a view
When a route only needs to return a view, useRoute::view for a concise definition:
Route parameters
Required parameters
Capture segments of the URI by defining route parameters wrapped in{}. The captured values are passed as arguments to the route callback:
Optional parameters
Make a parameter optional by adding? after its name and providing a default value for the corresponding argument:
Regular expression constraints
Constrain the format of a route parameter using thewhere method:
Named routes
Named routes let you reference a route by name when generating URLs or redirects, so you don’t need to hard-code URLs:Generating URLs to named routes
Use theroute helper to generate a URL from a route name:
Redirecting to named routes
Route groups
Group related routes to share middleware, controllers, prefixes, and other attributes without repeating them on each route.Middleware
Controllers
Group routes that share the same controller:Prefixes
Add a common URI prefix to a group of routes:Name prefixes
Prefix the name of every route in a group:Resource routes
For controllers that handle CRUD operations on a resource,Route::resource registers all the standard routes in one line:
| Verb | URI | Action | Route name |
|---|---|---|---|
| GET | /photos | index | photos.index |
| GET | /photos/create | create | photos.create |
| POST | /photos | store | photos.store |
| GET | /photos/{photo} | show | photos.show |
| GET | /photos/{photo}/edit | edit | photos.edit |
| PUT/PATCH | /photos/{photo} | update | photos.update |
| DELETE | /photos/{photo} | destroy | photos.destroy |
only or except:
Listing defined routes
Display all registered routes with the Artisan command:Next steps
Blade templates
Learn how to use Laravel’s Blade templating engine to build dynamic views.