Currently Available: Need a skilled Software Developer for your next project?
Categories
Laravel

What’s New in Laravel 13 Routing

Laravel 13 keeps the routing model developers already use, where routes map incoming HTTP requests to the code that handles them. This release introduces three practical updates. Laravel changes which route it picks when domain-specific routes overlap with general ones, lets you attach custom metadata to routes, and adds support for the HTTP QUERY method so clients can send query data in the request body.

These updates did not all ship at once. Laravel 13.0 launched on March 17, 2026, according to the Laravel release notes, and introduced the new matching priority so Laravel checks domain-specific routes before routes that accept any domain. Later Laravel 13.x releases added route metadata and QUERY support, so check your installed version before you rely on either feature.

Domain routes now take priority

When Laravel matches an incoming request, it now checks routes tied to a specific domain before it checks routes that accept requests on any domain. The Laravel 13 upgrade guide documents this change, which makes routing more predictable when your application mixes subdomain routes with broader ones.

Suppose your application serves account pages on {account}.example.com and also defines a general route that matches many paths. Laravel checks the {account}.example.com route first, even if you placed the general route higher up in the route file. Because file order no longer decides between those two routes, any application that depended on top-to-bottom ordering can route requests to a different handler after you upgrade.

Test your routes with representative host and path combinations, paying close attention to places where a catch-all route overlaps with a subdomain route.

Attaching custom metadata to routes

Laravel 13.x introduces metadata(), a method that lets you attach structured values to a route or a route group. Any route inside a group inherits the group's metadata, and individual routes can add new keys or override inherited ones. According to the framework changelog, Laravel keeps this metadata available during routing and preserves it when you cache routes.

Here is how a route group can define shared page metadata while a single route adds its own title:

Route::metadata([
    'head' => [
        'robots' => ['noindex'],
        'author' => 'Taylor',
    ],
])->group(function () {
    Route::get('/users', [UserController::class, 'index'])
        ->metadata(['head' => ['title' => 'Users']]);
});

Inside your controller or middleware, you can read those values from the matched route:

$title = $request->route()->getMetadata('head.title');
$author = $request->route()->getMetadata('head.author', 'Taylor');

The RouteGroup API documentation explains how nested metadata combines. Laravel merges key-value pairs at each nested level, while lists and other values replace whatever the parent group set. In the example above, the /users route adds head.title without wiping out robots or author.

Keep in mind that Laravel only stores these values for you. It does not render HTML meta tags or enforce access rules on its own. Your middleware, controllers, or views still need to read the metadata and act on it.

Handling HTTP QUERY requests with Route::query()

Laravel 13.x adds Route::query() so you can register routes for the HTTP QUERY method. Clients use QUERY to send query parameters in the request body, which helps when complex search criteria do not fit neatly into a URL. The Laravel routing documentation presents it as a dedicated option for body-based queries alongside GET.

use Illuminate\Support\Facades\Route;

Route::query('/products/search', SearchProductsController::class);

Two details matter when you wire up a QUERY route. First, if you place the route inside Laravel's web middleware group, Laravel applies CSRF protection to prevent forged cross-site requests, so browser requests must follow the same protection rules as other routes in that group. Second, declare specific routes like query() before broader routes like any(), match(), or redirect() whenever they share the same URI. Laravel's October changelog also notes that Route::any() matches QUERY requests.

Laravel's documentation covers how the framework routes QUERY requests, but it does not measure how widely clients, proxies, or hosting providers support the method. Test your clients and production infrastructure before you depend on QUERY in live traffic.

What to check when upgrading

If you are upgrading an existing app to Laravel 13, start by checking your domain routes. Any application that mixes subdomain routes with general or catch-all routes may match different handlers now that Laravel checks domain-specific routes first, so test those paths and update any routing logic that relied on the old file order.

Because metadata() and Route::query() arrived in later Laravel 13.x releases, a base 13.0 installation will not include them. Check your installed framework version and the routing documentation to confirm which route-registration methods and ordering rules apply to your app.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *