News

JSON Schema Validation Rules and a RetryFor Attribute in Laravel 13.43

Published
JSON Schema Validation Rules and a RetryFor Attribute in Laravel 13.43 image

The Laravel team released v13.43.0 with deriving validation rules from a JSON schema, a #[RetryFor] queue attribute, the ability to release a job using backoff, a RawTemplate class for inline Blade components, and several security fixes:

Validation Rules From a JSON Schema

Pushpak Chhajed contributed JsonSchema::rules(), which converts an object schema into Laravel validation rules. Tools in the Laravel AI SDK and Laravel MCP describe their input with a JSON schema, and until now you had to repeat the same constraints as validation rules:

use Illuminate\JsonSchema\JsonSchema;

$schema = JsonSchema::object(fn ($schema) => [
    'name' => $schema->string()->max(50)->required(),
    'age' => $schema->integer()->min(18),
    'role' => $schema->string()->enum(['admin', 'user'])->required(),
]);

JsonSchema::rules($schema);

// [
//     'name' => ['required', 'string', 'max:50'],
//     'age' => ['sometimes', RejectEmptyString, 'integer', 'min:18'],
//     'role' => ['required', 'string', Rule::in(['admin', 'user'])],
// ]

The method also accepts a raw schema array, and the result works anywhere Laravel takes rules, such as Validator::make() or a form request. Nested properties become dot-notation keys like address.city and tags.*.

See #62355 and #62496 for more details.

The RetryFor Queue Attribute

Francisco Madeira contributed a #[RetryFor] attribute that sets a job's retry window without a retryUntil() method:

use Illuminate\Queue\Attributes\RetryFor;

// Before
class ImportProducts implements ShouldQueue
{
    public function retryUntil(): DateTime
    {
        return now()->addHours(4);
    }
}

// After
#[RetryFor(hours: 4)]
class ImportProducts implements ShouldQueue
{
    //
}

The first argument is in seconds, and you can pass minutes and hours by name, as in #[RetryFor(hours: 1, minutes: 30)]. The attribute works on jobs, queued mailables, queued notifications, and queued listeners, and child classes inherit it. A retryUntil() method or $retryUntil property still takes precedence.

See #62434 for more details.

Release a Job Using Its Backoff

Francisco Madeira also added releaseUsingBackoff() to the InteractsWithQueue trait. The worker only applies a job's backoff when the job throws, so a job that releases itself, like one polling an API until a result is ready, had to look up the delay by hand:

#[Backoff(5, 15, 60, 300)]
class WaitForExport implements ShouldQueue
{
    use InteractsWithQueue;

    public function handle(): void
    {
        if (! $this->export->isReady()) {
            return $this->releaseUsingBackoff();
        }

        $this->export->download();
    }
}

The delay is the backoff value for the current attempt, and once attempts run past the end of the list, every release uses the last value. A job with no backoff is released with no delay.

See #62435 for more details.

RawTemplate for Inline Blade Components

@JurianArie contributed a RawTemplate class for inline components. When a component's render() method returns a string that isn't a view name, Blade compiles the string as a template. If that string includes user input, such as a user's name, any Blade syntax in the input runs on the server.

Returning a RawTemplate makes the intent explicit:

use Illuminate\View\RawTemplate;

public function render(): RawTemplate
{
    return new RawTemplate(<<<'blade'
        <div class="alert">{{ $message }}</div>
    blade);
}

The constructor's parameter is typed as a literal-string, so static analysis tools like PHPStan flag a template built from variables. The make:component --inline stub now returns a RawTemplate. Returning a plain string still works in Laravel 13.

See #62419 for more details.

Writes That Don't Affect Read Replica Stickiness

Jack Bayliss contributed withoutAffectingStickiness() to the database connection. With the sticky option enabled, any write sends the rest of the request's reads to the write connection. A write inside the callback, like a timestamp at the start of a job, leaves later reads on the read replica:

DB::withoutAffectingStickiness(function () {
    $this->task->update(['started_at' => now()]);
});

// Reads still go to the read connection
$this->task->run();

If the connection already had a write before the call, reads stay on the write connection.

See #62465 for more details.

Stringable isBlank() and isNotBlank()

Steve Bauman added isBlank() and isNotBlank() to fluent strings, which follow the same rules as the blank() helper:

// Before
blank(str($bio)->stripTags());

// After
str($bio)->stripTags()->isBlank();

str('   ')->isBlank(); // true
str('0')->isBlank();   // false

See #62415 for more details.

Security Fixes and Horizon 5.47

This release includes several security fixes from the 12.x branch. They cover temporary signed URLs whose expiration could be bypassed with array or numeric query parameters, XSS in component attributes and the debug page's "copy request URL" button, a mass-assignment guard bypass through mutator attribute names, a file validation bypass, and unbounded $ref chains in the JSON Schema deserializer.

The framework now also declares a conflict with laravel/horizon versions below 5.47.0, which are incompatible with the current framework release. If your app uses an older Horizon version, Composer will ask you to upgrade Horizon along with the framework.

Release Notes

You can see the complete list of new features and updates below and the diff between 13.42.0 and 13.43.0 on GitHub. The following release notes are directly from the changelog:

v13.43.0

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

serpapi logo
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi

The latest

View all →
Durable Workflow: Long-Running Workflows for Laravel image

Durable Workflow: Long-Running Workflows for Laravel

Read article
Session Replay for Laravel: Self-Hosted Browser Recordings image

Session Replay for Laravel: Self-Hosted Browser Recordings

Read article
Laravel AI SDK 1.4 Lets Agents Recover From Tool Failures image

Laravel AI SDK 1.4 Lets Agents Recover From Tool Failures

Read article
Laravel Read Replicas: Check if a Replica Has Caught Up image

Laravel Read Replicas: Check if a Replica Has Caught Up

Read article
UUID Request Input and Migration Failure Events in Laravel 13.42 image

UUID Request Input and Migration Failure Events in Laravel 13.42

Read article
Replay Missed Laravel Scheduled Tasks With Schedule Catchup image

Replay Missed Laravel Scheduled Tasks With Schedule Catchup

Read article