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.

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
Bacancy logo

Bacancy

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

Bacancy
Lucky Media logo

Lucky Media

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

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
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
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
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

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

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article
Register now for Sentry Launch Week! image

Register now for Sentry Launch Week!

Read article
Hide and safeguard emails from bots with the Muddle Laravel package image

Hide and safeguard emails from bots with the Muddle Laravel package

Read article
Dynamic Cache, Database, and Mail Builders in Laravel 11.31 image

Dynamic Cache, Database, and Mail Builders in Laravel 11.31

Read article
PHPStan 2.0 is Here image

PHPStan 2.0 is Here

Read article
Run multiple CLI commands locally at once with Solo for Laravel image

Run multiple CLI commands locally at once with Solo for Laravel

Read article