Laravel 9.2 Released

News

February 23rd, 2022

Laravel 9.2 Released

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:

1// Using the new keyword
2return (new Attribute(
3 get: fn ($value) => strtoupper($value),
4 set: fn ($value) => strtoupper($value)
5))->withoutObjectCaching();
6 
7// The new make() static constructor method
8return Attribute::make(
9 get: fn ($value) => strtoupper($value),
10 set: fn ($value) => strtoupper($value)
11)->withoutObjectCaching();

Array keyBy Method

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

1$array = [
2 ['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
3 ['id' => '345', 'data' => 'def', 'device' => 'tablet'],
4 ['id' => '345', 'data' => 'hgi', 'device' => 'smartphone'],
5];
6 
7Arr::keyBy($array, 'id');
8/*
9[
10 '123' => ['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
11 '345' => ['id' => '345', 'data' => 'hgi', 'device' => 'smartphone']
12 // The second element of an original array is overwritten by the last element because of the same id
13]
14*/

Expects Output to Contain Test Assertion

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

1$this->artisan('Hello World')
2 ->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:

1Str::betweenFirst('[a]ab[b]', '[', ']'); // a
2Str::betweenFirst('foofoobar', 'foo', 'bar'); // foo
3Str::betweenFirst('hannah', 'ha', 'ah'); // nn
4Str::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:

1$request->validate(
2 [
3 'foo' => [new Example]
4 ],
5 [
6 Example::class => 'My custom message goes here!'
7 ]
8);

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)

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.