BindWhen Container Attribute in Laravel 13.22

Last updated on by

BindWhen Container Attribute in Laravel 13.22 image

Laravel 13.22 adds a #[BindWhen] attribute for conditional container bindings, a Validator::fakeDnsLookups() method for testing DNS-backed validation rules, #[Delay] attribute support for batched and bulk-dispatched jobs, and comma-separated queue names in the queue:clear command. The Laravel team released v13.22.0 on July 24, 2026.

  • #[BindWhen] attribute for conditional container bindings
  • Fake DNS lookups in the active_url and email:dns validation rules
  • #[Delay] attribute support for Bus::batch() and Queue::bulk()
  • Multi-queue support in queue:clear
  • A macroable rate limiter, restored HTTP fake stream bodies, and assorted fixes

What's New

#[BindWhen] Attribute for Conditional Bindings

The #[Bind] attribute ties an interface to a concrete implementation, but its only conditional hook is the environments argument. The new #[BindWhen] attribute accepts a closure that receives the container, so a binding can depend on configuration, feature flags, or anything else resolvable at runtime:

use Illuminate\Container\Attributes\Bind;
use Illuminate\Container\Attributes\BindWhen;
 
#[BindWhen(BetaPaymentGateway::class, static function ($container) {
return $container->make('config')->get('features.payments.beta');
})]
#[Bind(FakePaymentGateway::class, environments: ['local', 'testing'])]
#[Bind(StripePaymentGateway::class)]
interface PaymentGatewayInterface {}

The attribute is repeatable and conditions are evaluated in declaration order, so conditional bindings can sit ahead of a default #[Bind] fallback. Note that closures in attribute arguments are a PHP 8.5 language feature. Contributed by @ziadoz in #60862.

Faking DNS Lookups in Validation

The active_url rule and the dns option on the email rule perform real DNS queries, which makes any test that exercises them dependent on the network and prone to random failures. A new fakeDnsLookups() method skips the lookup while keeping the rest of the validation intact:

use Illuminate\Support\Facades\Validator;
 
protected function setUp(): void
{
parent::setUp();
 
Validator::fakeDnsLookups();
}

Malformed URLs and email addresses still fail validation; only the network call is bypassed. Passing false turns the fake back off. Contributed by @SjorsO in #60879.

#[Delay] Attribute Support for Batches and Bulk Dispatch

Jobs that declare their delay with the #[Delay] attribute were delayed when dispatched individually, but Bus::batch() and Queue::bulk() only honored the $delay property and silently ignored the attribute. The queue drivers now check both, so the attribute behaves consistently across every dispatch path:

use Illuminate\Queue\Attributes\Delay;
 
#[Delay(15)]
class ProcessPodcast implements ShouldQueue
{
use Queueable;
}
 
Bus::batch([new ProcessPodcast])->dispatch();

Contributed by @jackbayliss in #60766.

Multi-Queue Support in queue:clear

The queue:clear command now accepts comma-separated queue names, matching the convention already used by queue:work and queue:listen:

php artisan queue:clear redis --queue=high,low,emails

Whitespace is trimmed and duplicate names are removed before clearing. Contributed by @miladshakerdn in #60873.

Other Fixes and Improvements

  • The RateLimiter class is now macroable (#60869), and the QueueFake implements creationTimeOfOldestPendingJob() so code that inspects queue age runs under Queue::fake() (#60730)
  • HTTP fake responses accept PSR-7 StreamInterface instances and PHP stream resources again, fixing a regression introduced by earlier body validation (#60834)
  • The JobReleasedAfterException event now carries the exception that caused the release (#60823)
  • Fixed the queue name parameter in Mailer::later() (#60865) and expiration handling in Cache::touch() (#60878)
  • Restored iterable support in Arr::every() and Arr::some() (#60876) and in Arr::last() (#60881)
  • HTTP testing credentials are marked as sensitive parameters so they stay out of stack traces (#60880)
  • Str::ucfirst() and Str::lcfirst() now use the native multibyte functions added in PHP 8.4 (#60864), and class attribute resolution now checks attributes declared on traits (#60566)

Upgrade Notes

No breaking changes are expected for typical applications. Keep in mind that #[BindWhen] relies on closures in attribute arguments, which requires PHP 8.5. Review the changelog for PR-by-PR details when upgrading.

References

Paul Redmond photo

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

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Acquaint Softtech

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

Visit Acquaint Softtech
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Laravel Cloud logo

Laravel Cloud

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

Laravel Cloud
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises

The latest

View all →
Building a Live Match Scoreboard With Laravel Reverb image

Building a Live Match Scoreboard With Laravel Reverb

Read article
Building and Deploying a Laravel App With Claude Code on Zerops image

Building and Deploying a Laravel App With Claude Code on Zerops

Read article
The first hands-on AI Developer Certification image

The first hands-on AI Developer Certification

Read article
Heimdall: A Minimum Age Policy for Your Composer Dependencies image

Heimdall: A Minimum Age Policy for Your Composer Dependencies

Read article
Laravel Announces the Founders Summit, a One-Day Event for Founders image

Laravel Announces the Founders Summit, a One-Day Event for Founders

Read article
A Practical Guide to Laravel's First-Party Image Processing image

A Practical Guide to Laravel's First-Party Image Processing

Read article