I called Route::query() and the router said Attribute [query] does not exist

I called Route::query() and the router said Attribute [query] does not exist

Laravel 13.35 adds Route::query() and an opt-in defaults() trait. On 13.34 that call is a group attribute and throws. QUERY in the web group still runs the CSRF middleware, and a feature test will not show the 419. Packagist this morning is 13.44.1.

· Updated · 9 min read #laravel #php #routing #eloquent

 13.34 has no Route::query(). 13.35 adds it. 13.44.1 is current and the contract still has no query()

Caption: Registrar.php is the same bytes on v13.34.0, v13.35.0, and v13.44.1. Router::query() exists from 13.35. HasDefaultAttributes.php matches on 13.35 and 13.44.1.

Introduction

The other draft from this morning is the 13.43 JsonSchema::rules() post. I am writing this one on 25 Nov 2026 (2026-W48). Nothing in the queue is tagged 2026-W48. The lowest undone row is 2026-W41, priority 14: Route::query() and model defaults(). Laravel News covered both on 7 Oct 2026. Packagist this morning is still v13.44.1. I did not boot an app.

About the feature

Route::query() lives on Illuminate\Routing\Router. On v13.35.0 and v13.44.1 the body is addRoute('QUERY', $uri, $action). $verbs adds QUERY after OPTIONS. any() passes that list, and redirect() calls any(), so a redirect matches QUERY too. fallback() is still GET only. addRoute() does not look at $verbs, so Route::match(['QUERY'], ...) could already register the verb on 13.34. The new piece is the method.

Illuminate\Contracts\Routing\Registrar has no query(). That file is the same bytes on v13.34.0, v13.35.0, and v13.44.1. The facade still resolves to the router, so Route::query() hits Router once the method exists.

On v13.34.0 there is no query() method. Router::__call() is not a macro, and the name is not middleware, can, or a where* rule, so the call becomes RouteRegistrar::attribute('query', $parameters[0]). The action argument is dropped. attribute() throws when the key is missing from $allowedAttributes:

InvalidArgumentException: Attribute [query] does not exist.

Route::middleware('web')->query(...) lands on RouteRegistrar::__call() instead. On 13.34, $passthru stops at any, so the registrar throws BadMethodCallException: Method Illuminate\Routing\RouteRegistrar::query does not exist. v13.35.0 adds query to $passthru, and that file matches v13.44.1. The query() body on Router matches too.

CSRF did not grow a case for this verb. PreventRequestForgery.php is the same bytes on those three tags. isReading() allows HEAD, GET, and OPTIONS. handle() then skips the token when runningUnitTests() is true, when the URI is in $except, or when Sec-Fetch-Site is same-origin. allowSameSite() defaults to false, so same-site still needs a token. A missing header falls through to tokensMatch(). A miss throws TokenMismatchException with CSRF token mismatch. Handler::prepareException() maps that to HTTP 419.

$this->query() has called $this->call('QUERY', ...) since at least v13.19.0. MakesHttpRequests.php matches from v13.34.0 through v13.44.1, so a feature test will not show the 419.

defaults() on this release is opt-in. HasDefaultAttributes::defaults() returns []. The trait file matches on v13.35.0 and v13.44.1 and is a 404 on v13.34.0. The constructor calls mergeDefaultAttributes(), then syncOriginal(), then fill($attributes). The merge returns unless class_uses_recursive finds the trait. From v13.43.0 that boolean is cached on Model::$classAttributes (PR #62432, 12 Nov 2026). The next line is unchanged:

$this->attributes = array_merge($this->attributes, $this->defaults());

defaults() overwrites the same key on the $attributes property. The write does not call setAttribute(), so set mutators and fromDateTime() do not run on the way in. A later read still calls transformModelValue(). getAttributesForInsert() returns getAttributes(), so save() sends that raw array, including values syncOriginal() already marked clean.

 QUERY misses isReading(). Unit tests and Sec-Fetch-Site same-origin skip the token. Otherwise 419

Caption: PreventRequestForgery::handle() on v13.44.1. A browser fetch from the same origin sends Sec-Fetch-Site: same-origin and never reaches tokensMatch(). curl does not send that header.

Why I picked it

Product search outgrew the query string. Brand, price, and a pile of attribute ids belong in a body, and POST on that URI creates a product. The test helper already spoke QUERY. 13.35 is the route method.

trial_days comes from config('billing.trial_days'), and cancelled starts as false. The $attributes property cannot call config(). defaults() can. Eloquent docs fetched 25 Nov 2026 (eloquent.md last touched 16 Nov 2026) still only show $attributes under "Default Attribute Values". Routing docs on the same branch (routing.md, 23 Nov 2026) already list Route::query() and say a web QUERY route is subject to CSRF. The CSRF section further down that page still names forms for POST, PUT, PATCH, and DELETE.

Where it can be used

I would use Route::query() for a search whose payload is JSON. On routes/web.php the session middleware is on the route. On routes/api.php the client is a token and this CSRF middleware is absent. Register query before redirect on a shared URI, because redirect() now matches QUERY.

defaults() is for a value computed at construction: config, a flag, or a date string the column already stores. I would not return now(), because fromDateTime() lives in setAttribute() and this path never calls it.

Benefit

Both APIs ship inside laravel/framework. I do not composer require illuminate/routing or illuminate/database. On v13.44.1, replace sets those two, plus illuminate/contracts, illuminate/http, illuminate/session, and illuminate/testing, to self.version. php is ^8.3. v13.35.0 composer.json matches v13.34.0. Its only conflict is tightenco/collect below 5.5.33.

v13.44.1 adds laravel/horizon below 5.47.0. I would bump to 13.44.1. The Releases API for v13.44.0 returns 404.

 laravel/framework 13.44.1 replaces routing, database, contracts, http, and session

Caption: php is ^8.3 on 13.35 and 13.44.1. Horizon older than 5.47.0 fails the solve only after the 13.43 conflict line. HasDefaultAttributes is a trait in the framework, not a package.

Practical example from a recent application

Lab shape from the 7 Oct Laravel News note, PR #61797, PR #61813, and tag v13.44.1. If composer show laravel/framework is still 13.34.x, stop. Route::query() is not a method on that tag.

composer show laravel/framework | sed -n '1,8p'
# name     : laravel/framework
# versions : * v13.44.1

Failure I hit if I paste Route::query() onto 13.34. I did not boot. On that tag, Route::query('/products/search', SearchProductsController::class) becomes attribute('query', '/products/search'), and the controller is never stored. The text in attribute() is Attribute [query] does not exist. Route::middleware('web')->query(...) is the other message, Method Illuminate\Routing\RouteRegistrar::query does not exist. The fix is 13.35.0 or newer. On 13.44.1 the method is real, and the passthru includes query.

use Illuminate\Support\Facades\Route;

Route::middleware('web')->group(function () {
    Route::query('/products/search', SearchProductsController::class);
});

Failure I hit if I curl that web route with no token. curl sends no Sec-Fetch-Site: same-origin, so tokensMatch() fails and prepareException() returns HTTP 419 with CSRF token mismatch. $this->query() skips that branch under runningUnitTests(). A same-origin browser fetch sends the header and also skips the token. I did not send either request. The server-side fix is _token, X-CSRF-TOKEN, or the X-XSRF-TOKEN cookie. An $except entry for that one path also passes. allowSameSite() still defaults to false.

Failure I hit if the model defines defaults() and I forget the trait. The merge returns before the call. The $attributes property is what you get, and there is no error. With the trait, array_merge replaces the property, syncOriginal() runs, then fill().

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasDefaultAttributes;
use Illuminate\Database\Eloquent\Model;

class Subscription extends Model
{
    use HasDefaultAttributes;

    protected $fillable = ['cancelled', 'trial_days'];

    protected $attributes = [
        'cancelled' => true,
        'trial_days' => 0,
    ];

    protected function defaults(): array
    {
        return [
            'cancelled' => false,
            'trial_days' => (int) config('billing.trial_days'),
        ];
    }
}

After new Subscription, getAttributes() has cancelled false and trial_days from config. Those beat the property. save() still inserts them, because getAttributesForInsert() returns getAttributes() even when syncOriginal() marked them clean.

Failure I hit if I pass an override the model will not fill. new Subscription(['cancelled' => true]) reaches fill() after the merge. Default $guarded is ['*']. With an empty $fillable, totallyGuarded() is true and fill() throws:

Illuminate\Database\Eloquent\MassAssignmentException: Add [cancelled] to fillable property to allow mass assignment on [App\Models\Subscription].

The $fillable list above is the fix, and it changes the winner: fill() calls setAttribute(), so the constructor array overwrites defaults().

Failure I hit if an old defaults() returns a string. Adding the trait calls it. Under PHP 8.3, array_merge with a string second argument throws:

TypeError: array_merge(): Argument #2 must be of type array, string given

Return the string the column already stores. fromDateTime() never runs on this path.

 $attributes, then defaults() via array_merge, then syncOriginal(), then fill()

Caption: Model::__construct() on v13.44.1. defaults() beats the property. The constructor array goes through fill() and can throw MassAssignmentException before you ever hold the instance.

Conclusion

What I would keep: laravel/framework at 13.44.1, Route::query('/products/search', ...) on the web group, and a token on any client that omits Sec-Fetch-Site: same-origin. A green $this->query() test is not proof the 419 is gone. Subscription keeps the trait, a raw trial_days from config, and both keys in $fillable. Horizon stays 5.47.0 or newer. Next I would check every Route::redirect() that shares a URI with search.

Did you hit the same wall?

I got stuck on InvalidArgumentException: Attribute [query] does not exist. when Route::query() was still a group attribute on 13.34, and on CSRF token mismatch. rendered as HTTP 419 from curl after the feature test had already passed. Did you hit the same thing — a Route::middleware()->query() chain that throws Method Illuminate\Routing\RouteRegistrar::query does not exist., a defaults() method that does nothing until the trait is on the class, or Add [cancelled] to fillable property to allow mass assignment when the constructor array overwrites the default? Tell me in the comments. I read them.

Need this done on your server?

I deploy and harden Laravel/CodeCanyon apps on cPanel or VPS, and offer monthly Server Watch retainers. Hire for deploy · Care plan

References

  • Laravel 13.x routing, routing.md last commit 23 Nov 2026 (91e8831934), retrieved 25 Nov 2026. Lists Route::query() and CSRF for web QUERY routes. The form section on that page still names POST, PUT, PATCH, and DELETE: https://laravel.com/docs/13.x/routing
  • Laravel 13.x Eloquent, eloquent.md last commit 16 Nov 2026 (4dc3b34cb1), retrieved 25 Nov 2026. "Default Attribute Values" shows $attributes only: https://laravel.com/docs/13.x/eloquent
  • Laravel News, 7 Oct 2026, "Route::query() and Model defaults() in Laravel 13.35" (Paul Redmond): https://laravel-news.com/laravel-13-35-0
  • PRs #61797, #61813, and #62432. HasDefaultAttributes.php SHA-256 7e128488f25860e0ba442f642124849d04f2b47c351eafbd1112ac41391deb44 on v13.35.0 and v13.44.1. PreventRequestForgery.php SHA-256 d636885af0f2c06d244a2dfb9ae754af89694c8e9f099ca94946cf5e37bbf04d on v13.34.0 through v13.44.1. Registrar.php SHA-256 818677dea453d59a2f4ce0caf298257714773904689f10ef898f0b213854744b on those three tags, with no query() method.
  • Tag v13.35.0, Packagist time 6 Oct 2026 13:52 UTC, published-time 13:53 UTC, GitHub release 13:54 UTC, sha a413a9da. Tag v13.44.1, Packagist time 24 Nov 2026 16:10 UTC, published-time 16:10 UTC, GitHub release 16:11 UTC, sha 8a8c4a84. The Releases API for v13.44.0 returns 404. v13.44.1 require includes php: ^8.3. Conflict: laravel/horizon below 5.47.0. No CVE number is claimed here.
Share:

Get new posts in your inbox

No spam. One short email per new article — practical PHP, Laravel, devops, and AI-assisted workflows.

Comments

Powered by GitHub Discussions via Giscus. A free GitHub account is required.