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

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
Running Laravel's Scheduler on Multiple Servers image

Running Laravel's Scheduler on Multiple Servers

Read article
Laravel Fake Assertions Now Accept Property Arrays image

Laravel Fake Assertions Now Accept Property Arrays

Read article
Route::query() and Model defaults() in Laravel 13.35 image

Route::query() and Model defaults() in Laravel 13.35

Read article
Laravel AI SDK 1.1 Adds Agent Skills and Cohere Chat image

Laravel AI SDK 1.1 Adds Agent Skills and Cohere Chat

Read article
VMPal: Give Your AI Agent a Whole Computer image

VMPal: Give Your AI Agent a Whole Computer

Read article
Synapse: A Dev Dashboard for Laravel AI SDK Agents image

Synapse: A Dev Dashboard for Laravel AI SDK Agents

Read article