Ehsan Bagherzadegan
Back to articles
6 min read

What's New in Laravel 13.35: QUERY Routes, Model Defaults, Cleaner Test Fakes, and Safer Multi-Server Scheduling

Laravel 13.35 adds HTTP QUERY route support, a dynamic defaults() method for models, property-array syntax for fake assertions, percentage memory limits for queue workers, and two scheduler helpers that make multi-server deployments safer.

Laravel 13.35 landed on October 7 with a handful of features that solve real problems: cleaner test assertions, a standard way to define dynamic model defaults, HTTP QUERY route support, percentage-based memory limits for queue workers, and two scheduler helpers that make multi-server deployments safer. Here is a practical walkthrough of each.

Route::query() — HTTP QUERY method support

The HTTP QUERY method (RFC 10008) carries a request body while remaining safe and idempotent. It is designed for search endpoints where filter payloads exceed query-string limits or become unwieldy.

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

QUERY is now part of the router's verb list, so Route::any() and Route::redirect() match it automatically. A practical note: in the web middleware group, CSRF protection treats QUERY like POST, so you either need a valid token or an except entry in VerifyCsrfToken.

When to reach for QUERY over GET with a query string? When the filter object is large, deeply nested, or contains arrays that would produce unreadable URLs. The trade-off is client support — not every HTTP library or CDN handles QUERY out of the box — so keep a GET fallback or document the requirement clearly.

Model defaults() with HasDefaultAttributes

Until now, default attribute values lived in the $attributes property. That works for static values but falls short when defaults depend on configuration, feature flags, or the current time. Laravel 13.35 introduces an opt-in defaults() method via the HasDefaultAttributes trait.

use Illuminate\Database\Eloquent\Concerns\HasDefaultAttributes;

class Subscription extends Model
{
    use HasDefaultAttributes;

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

Key behaviors:

  • Values from defaults() win over $attributes.

  • They are applied as raw values — casts and mutators do not run on them.

  • The method runs on every new Model() call, so you can return dynamic values (now(), feature-flag checks, config reads).

  • It is strictly opt-in; models without the trait are unaffected.

This replaces the pattern of overriding boot() or using observers to set computed defaults, keeping the logic next to the model definition where it is discoverable.

Property arrays in fake assertions

Testing that a job, event, or notification was dispatched with specific data used to require a callback:

// Before
Queue::assertPushed(ProcessPodcast::class, function (ProcessPodcast $job) use ($podcast, $user) {
    return $job->podcast->is($podcast)
        && $job->user->is($user)
        && $job->status === 'pending';
});

Laravel 13.35 lets you pass an associative array of public property names and expected values:

// After
Queue::assertPushed(ProcessPodcast::class, [
    'podcast' => $podcast,
    'user' => $user,
    'status' => 'pending',
]);

This works across assertPushed, assertNotPushed, assertPushedOn, assertDispatched, assertNotDispatched, assertSentTo, assertNotSentTo, and their Bus, Event, and Notification counterparts.

Comparison rules:

  • Most values use strict equality (===).

  • Eloquent models are compared via $model->is() (primary key, table, and connection).

  • Only public properties are checked — constructor promotion with public works, protected/private do not.

  • No dot notation for nested values; compare the top-level property.

The callback form remains available for complex logic (nested assertions, collections, conditional checks), but for the common case of verifying a handful of public properties, the array syntax is shorter and easier to scan.

Percentage memory limits for queue:work

queue:work --memory=128 has always accepted an absolute megabyte value. Now you can specify a percentage of the PHP process's memory_limit:

php artisan queue:work --memory=60%

With memory_limit=512M, the worker stops after the current job once it crosses ~307 MB. This is useful when you want the limit to scale with the container or PHP configuration rather than hard-coding a number.

Caveat: if memory_limit is -1 (the CLI default on many setups), the percentage resolves to a negative number and the worker will never stop for memory. You must set an explicit memory_limit for the worker process (via php -d memory_limit=512M artisan queue:work ... or in php.ini) for percentage limits to work.

Multi-server scheduler improvements

Two new methods address long-standing pain points when running the scheduler on multiple servers.

Schedule::alwaysOnOneServer()

Instead of chaining ->onOneServer() on every task, call this once in a service provider:

// AppServiceProvider::boot()
Schedule::alwaysOnOneServer();

All scheduled tasks now behave as if they had onOneServer() applied. This requires a shared cache store (Redis, Memcached, DynamoDB, or database) accessible by all servers. If your default cache driver is file or array, specify a shared one:

Schedule::useCache('redis');

Schedule::hasBeenInterruptedSince()

Long-running scheduled commands can now detect a deploy interruption and exit gracefully between batches.

Before deploying, run:

php artisan schedule:interrupt

In your command, record the start time and check periodically:

$startedAt = now();

foreach ($batches as $batch) {
    if ($this->hasBeenInterruptedSince($startedAt)) {
        $this->info('Deploy detected, stopping gracefully.');
        return;
    }

    $batch->process();
}

The method compares the interruption timestamp (stored in the shared cache) against the provided start time. If a deploy occurred after the command started, it returns true.

A typical zero-downtime deploy workflow:

php artisan schedule:interrupt
# switch release, run migrations, clear caches
php artisan queue:restart

This prevents a command that started on the old code from continuing into the new release with potentially incompatible state.

When to use what

FeatureReach for it when…
Route::query()Search endpoints with large/complex filter payloads; you control the clients.
defaults()Model defaults depend on config, feature flags, or the current time.
Property arrays in fakesVerifying public properties on jobs/events/notifications; you want readable tests.
--memory=60%Worker memory limits should scale with container/PHP config; you set an explicit memory_limit.
alwaysOnOneServer()You run the scheduler on multiple servers and want single-execution semantics without per-task noise.
hasBeenInterruptedSince()You have long-running scheduled commands and do zero-downtime deploys.

Gotchas to keep in mind

  • defaults() values skip casts/mutators. If you need casting, set the value in a model event or accessor instead.

  • Property-array assertions only check public properties. If your DTOs use readonly or promoted protected properties, stick with callbacks.

  • Percentage memory limits are a no-op when memory_limit=-1. Verify your worker process actually has a limit set.

  • alwaysOnOneServer() requires a shared cache. Using the database driver works but adds load; Redis or Memcached is preferred.

  • schedule:interrupt only affects commands that explicitly call hasBeenInterruptedSince(). It does not kill processes.

Takeaway

Laravel 13.35 is a quality-of-life release. None of these features are flashy, but each removes a small piece of boilerplate or a deployment risk. The property-array assertions and defaults() method will likely see daily use in most codebases; the scheduler helpers are essential if you run on multiple servers. Upgrade, enable the traits and options you need, and delete the workarounds you had before.

Sources