Laravel 9.2 Released

Published on by

Laravel 9.2 Released image

The Laravel team released version 9.2.0 with an array keyBy method, an Eloquent attribute static constructor, moving the Laravel CORS package into the framework, and more:

Attribute Make Method

@ARI contributed a static constructor method to the Eloquent Attribute class, which provides convenience as follows:

// Using the new keyword
return (new Attribute(
get: fn ($value) => strtoupper($value),
set: fn ($value) => strtoupper($value)
))->withoutObjectCaching();
 
// The new make() static constructor method
return Attribute::make(
get: fn ($value) => strtoupper($value),
set: fn ($value) => strtoupper($value)
)->withoutObjectCaching();

Array keyBy Method

Douglas Medeiros contributed an Arr::keyBy() method which works like the collection keyBy() method:

$array = [
['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
['id' => '345', 'data' => 'def', 'device' => 'tablet'],
['id' => '345', 'data' => 'hgi', 'device' => 'smartphone'],
];
 
Arr::keyBy($array, 'id');
/*
[
'123' => ['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
'345' => ['id' => '345', 'data' => 'hgi', 'device' => 'smartphone']
// The second element of an original array is overwritten by the last element because of the same id
]
*/

Expects Output to Contain Test Assertion

Francisco Madeira contributed a expectsOutputToContain test method to assert that artisan commands contain a substring of output:

$this->artisan('Hello World')
->expectsOutputToContain('Hello');

Add X headers when using Mail::alwaysTo

Craig Morris contributed adding X headers in development when using the Mail::alwaysTo() method:

When using Mail::alwaysTo in development environments, the original To, Cc and Bcc are lost. This makes it difficult to determine where the email was going to during testing.

This PR adds the original to, cc and bcc into X-Headers in the email so this information can be retrieved, while still preventing the email being sent to these recipients.

This is useful for debugging the intended to, cc, and bcc fields, yet only sending email to the specified alwaysTo address. Check out Pull Request #41101 for details.

Integrate Laravel CORS into framework

Dries Vints migrated the fruitcake/laravel-cors package into the Laravel framework:

The main reason is that we want to remove a circular dependency we rely on additionally to the fact that we eliminate another dependency of the skeleton.

All credits for the code go to @barryvdh of @fruitcake . Thanks for maintaining that package for so long!

String "Between First" Method

Yoeri Boven contributed a betweenFirst() method which gets the smallest possible portion of a string between two given values:

Str::betweenFirst('[a]ab[b]', '[', ']'); // a
Str::betweenFirst('foofoobar', 'foo', 'bar'); // foo
Str::betweenFirst('hannah', 'ha', 'ah'); // nn
Str::betweenFirst('dddabcddd', 'a', 'c')); // b

Allow Specifying a Custom Message for Rule Objects

Ryan Chandler contributed a way to specify a custom error message when validating with a Rule object. With this update, you can provide a custom message to the messages array:

$request->validate(
[
'foo' => [new Example]
],
[
Example::class => 'My custom message goes here!'
]
);

Release Notes

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

v9.2.0

Added

  • Added Illuminate/Database/Eloquent/Casts/Attribute::make() (#41014)
  • Added Illuminate/Collections/Arr::keyBy() (#41029)
  • Added expectsOutputToContain to the PendingCommand. (#40984)
  • Added ability to supply HTTP client methods with JsonSerializable instances (#41055)
  • Added Illuminate/Filesystem/AwsS3V3Adapter::getClinet() (#41079)
  • Added Support for enum in Builder::whereRelation (#41091)
  • Added X headers when using Mail::alwaysTo (#41101)
  • Added of support Bitwise operators in query (#41112)
  • Integrate Laravel CORS into framework (#41137)
  • Added Illuminate/Support/Str::betweenFirst() (#41144)
  • Allow specifiying custom messages for Rule objects (#41145)

Fixed

  • Fixed Queue Failed_jobs insert issue with Exception contain UNICODE (#41020)
  • Fixes attempt to log deprecations on mocks (#41057)
  • Fixed loadAggregate not correctly applying casts (#41050)
  • Do not transform JsonSerializable instances to array in HTTP client methods (#41077)
  • Fix parsing config('database.connections.pgsql.search_path') (#41088)
  • Eloquent: firstWhere returns Object instead of NULL (#41099)
  • Fixed updated with provided qualified updated_at (#41133)
  • Fix setPriority Call for MailChannel (#41120)
  • Fixed route:list command output (#41177)
  • Fix database migrations $connection property (#41161)

Changed

  • Cursor pagination: convert original column to expression (#41003)
  • Cast $perPage to integer on Paginator (#41073)
  • Restore S3 client extra options (#41097)
  • Use latest() within notifications() in Illuminate/Notifications/HasDatabaseNotifications.php (#41095)
  • Remove duplicate queries to find batch (#41121)
  • Remove redundant check in FormRequest::validated() (#41115)
  • Illuminate/Support/Facades/Storage::fake() changed (#41113)
  • Use coalesce equal as provided by PHP >= 7.4 (#41174)
  • Simplify some conditions with is_countable() (#41168)
  • Pass AWS temporary URL options to createPresignedRequest method (#41156)
  • Let Multiple* exceptions hold the number of records and items found (#41164)
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
Tinkerwell

Version 4 of Tinkerwell is available now. Get the most popular PHP scratchpad with all its new features and simplify your development workflow today.

Visit Tinkerwell
Laravel Forge logo

Laravel Forge

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

Laravel Forge
Tinkerwell logo

Tinkerwell

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

Tinkerwell
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 $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
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
LoadForge logo

LoadForge

Easy, affordable load testing and stress tests for websites, APIs and databases.

LoadForge
Paragraph logo

Paragraph

Manage your Laravel app as if it was a CMS – edit any text on any page or in any email without touching Blade or language files.

Paragraph
Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
Bacancy - Staff Augmentation logo

Bacancy - Staff Augmentation

Leave your web app development hustles to the leading IT Staff Augmentation Service Providers. Choose from an extensive pool of 1050+ developers and give yourself the sigh of success you deserve with Bacancy. Get In Touch Today!

Bacancy - Staff Augmentation
DocuWriter.ai logo

DocuWriter.ai

Save hours of manually writing Code Documentation, Comments & DocBlocks, Test suites and Refactoring.

DocuWriter.ai
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector

The latest

View all →
Laracon EU Videos are now out image

Laracon EU Videos are now out

Read article
Use Google's Gemini AI in Laravel image

Use Google's Gemini AI in Laravel

Read article
PhpStorm is getting a brand new terminal image

PhpStorm is getting a brand new terminal

Read article
Six Essential Plugins for Visual Studio Code image

Six Essential Plugins for Visual Studio Code

Read article
Modularize Your Laravel Application With the Modular Package image

Modularize Your Laravel Application With the Modular Package

Read article
Handle Money Transactions in Eloquent with Laravel Wallet image

Handle Money Transactions in Eloquent with Laravel Wallet

Read article