Laravel 9.10 Released

News

April 28th, 2022

Laravel 9.10 Released

The Laravel team released 9.10 with a findOr() Eloquent method, a new command assertion, retrieve input as a Stringable instance, and more:

Before Refreshing Database Function

Rok Sprogar contributed a beforeRefreshingDatabase to the RefreshDatabase trait. This allows you to run code before the database starts refreshing:

1class DataExportTest extends TestCase
2{
3 use RefreshDatabase;
4 
5 protected $seed = true;
6 
7 protected function beforeRefreshingDatabase()
8 {
9 $this->artisan('db:wipe --database another-database-connection');
10 }
11 
12 // ...
13}

Does Not Expect Output Command Assertion

Markus Hebenstreit contributed a doesntExpectOutputToContain Command assertion method which is self-explanitory:

1Artisan::command('contains', function () {
2 $this->line('My name is Taylor Otwell');
3});
4 
5$this->artisan('contains')
6 ->doesntExpectOutputToContain('Taylor Otwell');

Eloquent "findOr" Method

Jess Archer contributed a findOr() method to the Eloquent builder and relations. This method matches the existing firstOr() methods:

1User::findOr(1, fn () => throw new RuntimeException);
2User::findOr(1, fn () => abort(403));
3User::findOr(1, fn () => 'return something');
4User::findOr(1, ['columns'], fn () => '...');
5 
6// Also works with relations
7$user->posts()->findOr(1, fn () => '...');

Customizable Compiled Extension

Taylor Otwell contributed a configurable compiled view extension that is customizable via the view configuration when passed into the blade compiler:

1new BladeCompiler(
2 $app['files'],
3 $app['config']['view.compiled'],
4 $app['config']->get('view.relative_hash', false) ? $app->basePath() : '',
5 $app['config']->get('view.cache', true),
6 $app['config']->get('view.compiled_extension', 'php'),
7);

Support for "IS" and "IS NOT" PostgreSQL Operators

Markus Koch contributed support for is and is not operators when using PostgreSQL. See Pull Request #42123 for details.

Retrieve Input from the Request as Stringable

Cameron Wilby and Taylor Otwell contributed the ability to retreive input from the request as a Stringable instance:

1$name = $request->string('name');
2// or
3$name = $request->str('name');

Append and Prepend Jobs to Existing Chain

Jan-Oliver Pantel contributed prependToChain() and appendToChain methods to append and prepend jobs:

The use case for that is whenever a job within a chain want's [sic] to enqueue jobs onto it's own chain without the need to create a new one and wait for successful execution of the "child chain".

This is technically already possible since all the needed properties and methods are public. However having formalized functions for that makes for a better DX.

See Pull Request #42138 for details.

Release Notes

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

v9.10.0

Added

  • Add the ability to use alias when performing upsert via MySQL (#42053)
  • Illuminate/Routing/Router::middlewareGroup() will support array of the middlewares (#42004, e6b84fb)
  • Added Missing AsCommand attribute on schedule:list (#42069)
  • Add the beforeRefreshingDatabase function to the Testing/RefreshDatabase trait (#42073)
  • Added doesntExpectOutputToContain assertion method (#42096)
  • Added a findOr method to Eloquent (#42092)
  • Allow extension in Illuminate/View/Compilers/Compiler.php (68e41fd)
  • Support 'IS' and 'IS NOT' PostgreSQL operators (#42123)
  • Added str and string methods to Illuminate/Http/Concerns/InteractsWithInput (c9d34b7)
  • Added methods to append and prepend jobs to existing chain (#42138)

Fixes

  • Make it so non-existent jobs run down the failed path instead of crashing (#42079)
  • Fix schedule:work command Artisan binary name (#42083)
  • Fix TrimStrings middleware with non-UTF8 characters (#42065)
  • Copy locale and defaultLocale from original request in Request::createFrom() (#42080)
  • Fix ViewErrorBag for JSON session serialization (#42090)
  • Fix array keys from cached routes in CompiledRouteCollection::getRoutesByMethod() (#42078)
  • Fix json_last_error issue with JsonResponse::setData (#42125)
  • Fix bug in BelongsToMany where non-related rows are returned (#42087)
  • Fix HasAttributes::mutateAttributeForArray when accessing non-cached attribute (#42130)

Changed

  • Make password rule errors translatable (#42060)
  • Redesign of the event:list Command. (#42068)
  • Changed event:list command (#42084)
  • Throw LostDbConnectionException instead of LogicException (#42102)
  • Throw deadlock exception (#42129)
  • Support Arr::forget() for nested ArrayAccess objects (#42142)
  • Allow Illuminate/Collections/Enumerable::jsonSerialize() to return other types (#42133)
  • Update schedule:list colouring output (#42153)

Filed in:

Paul Redmond

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