News

Queue totalSize() and JobInterrupted Event in Laravel 13.31

Published
Queue totalSize() and JobInterrupted Event in Laravel 13.31 image

Release updates

Never miss a Laravel release

Get an email whenever a new Laravel release lands.

The Laravel team released v13.31.0 with a queue connection totalSize() method, a new JobInterrupted event, chaperone support for BelongsToMany pivot models, and more.

Queue Total Size

Jack Bayliss contributed the totalSize() method, which answers the question "how many total jobs do I have on my queue connection right now?"

// Before
Queue::totalPendingSize() +  Queue::totalDelayedSize() + Queue::totalReservedSize(); 

// After
Queue::totalSize();

See #61373 for more details.

Job Interrupted Event

Jack Bayliss contributed a new JobInterrupted event that is fired when a job holding the Interruptible contract is interrupted by the worker. This allows you to listen for this event and perform any necessary cleanup or logging.

use Illuminate\Queue\Events\JobInterrupted;

Event::listen(JobInterrupted::class, function (JobInterrupted $event) {
    // Handle the job interruption
});

See #61412 for more details.

Chaperone Support for BelongsToMany Pivot Models

Caleb White contributed chaperone support for BelongsToMany pivot models. This allows you to use the chaperone() method on a BelongsToMany relationship to retrieve the pivot model instance.

Many times when using custom pivot models, the BelongsTo relations can be defined on the model---however, trying to use them requires loading the models from the database even though both of the models are available during the BelongsToMany hydration.

...This PR adds chaperone support to the BelongsToMany relation, if a custom pivot model is not provided then calling ->chaperone() is a no-op.

class PostTagPivot extends Pivot
{
    public function post(): BelongsTo
    {
        return $this->belongsTo(Post::class);
    }

    public function tag(): BelongsTo
    {
        return $this->belongsTo(Tag::class);
    }
}

class Tag extends Model
{
    public function posts(): BelongsToMany
    {
        return $this->belongsToMany(Post::class)
            ->using(PostTagPivot::class)
            // automatically guesses relationship names
            ->chaperone();
            // but can override if needed or non-standard
            ->chaperone(declaring: 'tag', related: 'post');
    }
}

class Post extends Model
{
    public function tags(): BelongsToMany
    {
        return $this->belongsToMany(Tag::class)
            ->using(PostTagPivot::class)
            ->chaperone(declaring: 'post', related: 'tag');
    }
}

See #61152 for more details.

Vite Dev Server URL

@ramonmalcolm10 contributed a devServerUrl() method to the Vite class, which allows you to retrieve the URL of the Vite development server. This is useful for generating asset URLs in your application.

See #61465 for more details.

Once Assertions for Mail and Notification Fakes

@talaridisTh contributed new "once" assertions for the Mail and Notification fakes:

// Before
Mail::assertSentTimes(OrderShipped::class, 1);
Mail::assertQueuedTimes(OrderShipped::class, 1);

Notification::assertSentToTimes($user, InvoicePaid::class, 1); 
Notification::assertSentOnDemandTimes(InvoicePaid::class, 1); 

// After
Mail::assertSentOnce(OrderShipped::class);
Mail::assertQueuedOnce(OrderShipped::class);

Notification::assertSentToOnce($user, InvoicePaid::class);
Notification::assertSentOnDemandOnce(InvoicePaid::class);

See #61415 for more details.

Release Notes

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

v13.31.0

Paul Redmond photo

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

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
PhpStorm 2026.3 Adds an Agent Workspace and PHP 8.6 Support image

PhpStorm 2026.3 Adds an Agent Workspace and PHP 8.6 Support

Read article
Insert Middleware Before or After Existing Laravel Middleware image

Insert Middleware Before or After Existing Laravel Middleware

Read article
Laravel Herd 2: Coding Agents, Workspaces, and Cloud Deploys image

Laravel Herd 2: Coding Agents, Workspaces, and Cloud Deploys

Read article
Strict Request Input Casting in Laravel image

Strict Request Input Casting in Laravel

Read article
Prevent Duplicate File Uploads With Laravel Storage Dedupler image

Prevent Duplicate File Uploads With Laravel Storage Dedupler

Read article
Slow Job Alerts and Replica Commit IDs in Laravel 13.40 image

Slow Job Alerts and Replica Commit IDs in Laravel 13.40

Read article