Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Laravel 9.12 Released

Published on by

Laravel 9.12 Released image

Never Miss a Laravel Release 🚀

Sign up and get an email with each new Laravel release

The Laravel team released 9.12 with delaying notifications per channel, sharing logging context across channels, preventing stray HTTP requests while testing, and more:

Closure-based Exception Testing

Karel Faille contributed a assertThrows() method which adds a way to test exception handling using closures:

// Ensure that an exception is thrown
$this->assertThrows(fn () => throw Exception(''));
 
// Ensure that a specific type of exception is thrown
$this->assertThrows(
fn () => (new SomeActionThatThrowsExceptions)->execute(),
CustomException::class
);
 
// Ensure that an exception is thrown with a specific message
$this->assertThrows(fn () => throw Exception('My message'), Exception::class, 'My message');

Force HTTP Requests to Be Faked in Tests

Tim MacDonald contributed the ability to force all HTTP requests using Laravel's HTTP client to be faked. If an HTTP request is not faked in a test, the test will throw an exception:

protected function setUp(): void
{
parent::setUp();
 
Http::preventStrayRequests();
}
 
public function testItDoesTheThingWithoutFaking(): void
{
$this->post('endpoint-that-utilises-the-http-facade');
 
// RuntimeException: Attempted request to [https://acme.com] without a matching fake.
 
/* ... */
}

"Throw If" HTTP Client Method

@denniseilander contributed a throwIf() method to the HTTP client that will throw an exception if the condition evaluates to true:

// Throws RequestException
return Http::baseUrl('https://foo.bar')
->throwIf(true)
->get('not-found');
 
// Doesn't throw
return Http::baseUrl('https://foo.bar')
->throwIf(false)
->get('not-found');

Allow Passing Key/Value Arrays to Artisan Options and Arguments

Jesper Noordsij contributed passing key/value arrays to getArguments and getOptions on Artisan commands for a slightly easier interface.

// Also, it is possible to skip those you don't want to use without providing/copying the default value
 
// e.g.
public function getArguments()
{
return [
['name' => 'argument', 'default' => 'default']
];
 
// which previously would have been...
// return [
// ['argument', null, '', 'default']
// ];
}

See Pull Request #42268 for more details.

New More Condition Methods

Patrick O'Meara contributed the inverse of whereMorphedTo and orWhereMorphedTo methods. Here's an example from the PR tests:

$model = new EloquentBuilderTestModelParentStub;
 
$this->mockConnectionForModel($model, '');
 
$relatedModel = new EloquentBuilderTestModelCloseRelatedStub;
 
$relatedModel->id = 1;
 
$builder = $model->whereNotMorphedTo('morph', $relatedModel);
 
$this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where not ("morph_type" = ? and "morph_id" = ?)', $builder->toSql());
 
$this->assertEquals([$relatedModel->getMorphClass(), $relatedModel->getKey()], $builder->getBindings());

Check out Pull Request #42264 for more details.

Share Logging Context Across Channels and Stacks

Tim MacDonald contributed sharing contextual information across all logging channels:

// In a service provider...
public function boot()
{
Log::shareContext([
'invocation-id' => (string) Str::uuid(),
]);
}

See contextual information in the logging documentation.

Delaying Notifications Per Channel

You can pass an array to the delay method to specify the delay amount for specific channels:

$user->notify((new InvoicePaid($invoice))->delay([
'mail' => now()->addMinutes(5),
'sms' => now()->addMinutes(10),
]));

You can also define a withDelay method on the notification class:

/**
* Determine the notification's delivery delay.
*
* @param mixed $notifiable
* @return array
*/
public function withDelay($notifiable)
{
return [
'mail' => now()->addMinutes(5),
'sms' => now()->addMinutes(10),
];
}

See Delaying Notifications Per Channel in the notifications documentation.

Release Notes

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

v9.12.0

Added

  • Added closure based exceptions testing (#42155)
  • Allow forcing requests made via the Http client to be faked (#42230)
  • Added 'throwIf' method to PendingRequest (#42260)
  • Allow passing key/value arrays to getArguments and getOptions (#42268)
  • Add whereNotMorphedTo, orWhereNotMorphedTo (#42264)
  • Add method to extend localeArray generation (#42275)
  • Added ability to set delay per channel based on notifiable instance (#42239)
  • Added Illuminate/Pagination/CursorPaginator::onLastPage() (#42301)
  • Added findOr method to Query/Builder (#42290)

Fixed

  • Fix too many channels with pusher broadcasting (#42287)
  • Fix Str::Mask() for repeating chars (#42295)
  • Fix EventFake::assertListening() for asserting string-based observer listeners (#42289)
  • Fixed Loose comparison causes the value not to be saved (#41337)
  • Fix multiple dots for digits_between rule (#42330)

Changed

  • Enable to modify HTTP Client request headers when using beforeSending() callback (#42244)
  • Make throttle lock acquisition retry configurable for concurrency limiter (#42242)
  • Defers expanding callables on Factories (#42241)
  • Add wherehas soft deleting scopes (#42100)
  • Improve password checks (#42248)
  • Set relation parent key when using forceCreate on HasOne and HasMany relations (#42281)
  • Make sure the prefix override behaviours are the same between phpredis and predis drivers (#42279)
  • Share logging context across channels and stacks (#42276)
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
Laravel Cloud

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

Visit Laravel Cloud
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

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

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

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

PhpStorm
Laravel Cloud logo

Laravel Cloud

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

Laravel Cloud
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

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

Shift
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
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

The latest

View all →
Automate Laravel Herd Worktrees with This Claude Code Skill image

Automate Laravel Herd Worktrees with This Claude Code Skill

Read article
Laravel Boost v2.0 Released with Skills Support image

Laravel Boost v2.0 Released with Skills Support

Read article
Laravel Debugbar v4.0.0 is released image

Laravel Debugbar v4.0.0 is released

Read article
Radiance: Generate Deterministic Mesh Gradient Avatars in PHP image

Radiance: Generate Deterministic Mesh Gradient Avatars in PHP

Read article
Speeding Up Laravel News With Cloudflare image

Speeding Up Laravel News With Cloudflare

Read article
Livewire 4 Support in Laravel VS Code Extension v1.4.3 image

Livewire 4 Support in Laravel VS Code Extension v1.4.3

Read article