Skip to main content

Basic routing

The most basic Laravel routes accept a URI and a closure. They let you easily define routes and their behavior without complex configuration files.

The default route files

All Laravel routes are defined in route files in the routes/ directory. These files are automatically loaded by Laravel based on the configuration in bootstrap/app.php. Define browser-facing routes in routes/web.php. Routes in this file are wrapped in the web middleware group, which provides session, CSRF protection, and cookie encryption.

API routes

If your application will offer a stateless API, you can enable API routing with the install:api Artisan command.
The install:api command installs Laravel Sanctum and creates a routes/api.php file. Sanctum provides a simple, robust API token authentication guard for third-party API consumers, SPAs, and mobile applications.
Routes in routes/api.php are stateless and the api middleware group is applied. The /api URI prefix is also automatically applied to every route, so you don’t need to add it manually. To change the prefix, edit your application’s bootstrap/app.php file.

Available HTTP methods

The router allows you to register routes for any HTTP verb.
Use match or any for a route that responds to multiple HTTP verbs.
Any HTML form that accepts POST, PUT, PATCH, or DELETE in a web route file must include the @csrf directive. Otherwise, the request will be rejected.

Routes that return views

If a route only needs to return a view, you can write it concisely with Route::view.

Route parameters

Required parameters

To capture a dynamic part of the URL, use route parameters. Wrap the parameter in {} and receive it as an argument on the route callback.
You can also define multiple parameters.
Route parameters cannot contain the / character.

Optional parameters

To make a parameter optional, append ? to the parameter name and give the corresponding argument a default value.

Regular expression constraints

You can constrain the format of parameters with regular expressions using the where method.
For common patterns, there are convenience methods you can use instead.

Named routes

Named routes let you refer to a route by name when generating URLs or redirects.

Generating URLs to named routes

To generate a URL from a route name, use the route helper.

Redirecting

Route groups

You can group related routes to share middleware, controllers, prefixes, and more.

Middleware

Controllers

You can group routes that use the same controller.

Prefixes

You can apply a common prefix to a set of route URIs.

Listing routes

To list every route that has been defined, use the Artisan command.
Include middleware information as follows:
To display only routes that start with a specific URI:

Next steps

Views

Learn how to create views and pass data to them from controllers.
Last modified on July 13, 2026