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?"
// BeforeQueue::totalPendingSize() + Queue::totalDelayedSize() + Queue::totalReservedSize(); // AfterQueue::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:
// BeforeMail::assertSentTimes(OrderShipped::class, 1);Mail::assertQueuedTimes(OrderShipped::class, 1); Notification::assertSentToTimes($user, InvoicePaid::class, 1);Notification::assertSentOnDemandTimes(InvoicePaid::class, 1); // AfterMail::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
- [12.x] Ensure password hash matches stored cookie before authenticating the user by @crynobone in https://github.com/laravel/framework/pull/61386
- [12.x] Fix TypeError in userFromRecaller() when the recaller matches no user by @lazerg in https://github.com/laravel/framework/pull/61397
- [13.x] Add totalSize method to Queue by @jackbayliss in https://github.com/laravel/framework/pull/61373
- Merge branch '12.x' into 13.x by @crynobone in https://github.com/laravel/framework/pull/61399
- [13.x] Restore the container instance after route:cache boots a fresh application by @lazerg in https://github.com/laravel/framework/pull/61405
- [13.x] Include connection and queue on WorkerStopping when worker is killed by @jackbayliss in https://github.com/laravel/framework/pull/61408
- [13.x] Fix lazy() and lazyById() ignoring limit() and offset() by @xurshudyan in https://github.com/laravel/framework/pull/61402
- [13.x]
JobInterruptedevent by @jackbayliss in https://github.com/laravel/framework/pull/61412 - [13.x] Make the Redis queue driver cluster-safe (
bulk()node-lessMULTI;allQueueNames()usesKEYS) by @Orrison in https://github.com/laravel/framework/pull/61198 - [13.x] feat: add chaperone support for BelongsToMany pivot models by @calebdw in https://github.com/laravel/framework/pull/61152
- Dedupe common test fixtures by @jasonmccreary in https://github.com/laravel/framework/pull/61422
- [13.x] feat: improve higher order proxy generic types by @calebdw in https://github.com/laravel/framework/pull/61418
- Apply fixes from StyleCI by @taylorotwell in https://github.com/laravel/framework/pull/61427
- [13.x] Add
onceassertions to the mail and notification fakes by @talaridisTh in https://github.com/laravel/framework/pull/61415 - Let Monolog handle deprecation exceptions by @sysdev34-wq in https://github.com/laravel/framework/pull/61414
- [13.x] Default
memoryExceededExitCodefor Cloud by @jackbayliss in https://github.com/laravel/framework/pull/61430 - [13.x] Fix context not being propagated to concurrent processes by @newtonjob in https://github.com/laravel/framework/pull/61419
- [13.x] Remove the unused Request import from the JSON:API resource stub by @Bosun18 in https://github.com/laravel/framework/pull/61434
- [13.x] Memory leak fix in Http Client by @skr4dan in https://github.com/laravel/framework/pull/61438
- [13.x] Fix SelfBuilding build stack cleanup after exceptions by @emrebalasar in https://github.com/laravel/framework/pull/61454
- [13.x] defer all logic to the dedicated rule by @browner12 in https://github.com/laravel/framework/pull/61445
- Wrap the closure return type in
withFreshQueryLog()by @SanderMuller in https://github.com/laravel/framework/pull/61444 - [13.x] Fix
assertJsonMissingPath()ignoring wildcards by @xurshudyan in https://github.com/laravel/framework/pull/61441 - [13.x] Resolve the
UsePolicyattribute from parent classes by @xurshudyan in https://github.com/laravel/framework/pull/61439 - [13.x] Resolve the
UseEloquentBuilderattribute from parent classes by @xurshudyan in https://github.com/laravel/framework/pull/61440 - [13.x] Fix parameter docblocks that contradict the native signature by @dfinchenko in https://github.com/laravel/framework/pull/61457
- Bump softprops/action-gh-release from 3.0.2 to 3.0.3 in the github-actions group by @dependabot[bot] in https://github.com/laravel/framework/pull/61468
- [13.x] Fix RateLimited job middleware hitting limits that did not block the job by @xurshudyan in https://github.com/laravel/framework/pull/61449
- [13.x] Add
devServerUrl()to Vite by @ramonmalcolm10 in https://github.com/laravel/framework/pull/61465 - [13.x] Retry phpredis commands when a connection reset surfaces as a warning by @Orrison in https://github.com/laravel/framework/pull/61462
- [13.x] Fix callbacks deferred from within a deferred callback by @newtonjob in https://github.com/laravel/framework/pull/61431
- [13.x] Propagate command_retries to phpredis cluster connections by @Orrison in https://github.com/laravel/framework/pull/61460
- [13.x] Qualify soft delete column with the query's table alias by @arunarw in https://github.com/laravel/framework/pull/61456
- [13.x] Keep Eloquent on the direct connection during migrations by @danielebarbaro in https://github.com/laravel/framework/pull/61435
- Apply fixes from StyleCI by @taylorotwell in https://github.com/laravel/framework/pull/61470
- [13.x] Fix Class
Illuminate\Session\ArraySessionHandlerimplementingSessionHandlerInterfaceis missing thecreate_sid()method which will be required in PHP 9.0 by @crynobone in https://github.com/laravel/framework/pull/61469 - Fix route url generation under certain circumstances by @taylorotwell in https://github.com/laravel/framework/pull/61475
- [13.x] Fix message ID and header persistence on ResendTransport by @saurabhsharma2u in https://github.com/laravel/framework/pull/61476
- [13.x] Fix wherePivot() closure scope being ignored in pivot table operations by @iz-ahmad in https://github.com/laravel/framework/pull/61488