Laravel 9.10 Released
Published on by Paul Redmond
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:
class DataExportTest extends TestCase{ use RefreshDatabase; protected $seed = true; protected function beforeRefreshingDatabase() { $this->artisan('db:wipe --database another-database-connection'); } // ...}
Does Not Expect Output Command Assertion
Markus Hebenstreit contributed a doesntExpectOutputToContain
Command assertion method which is self-explanitory:
Artisan::command('contains', function () { $this->line('My name is Taylor Otwell');}); $this->artisan('contains') ->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:
User::findOr(1, fn () => throw new RuntimeException);User::findOr(1, fn () => abort(403));User::findOr(1, fn () => 'return something');User::findOr(1, ['columns'], fn () => '...'); // Also works with relations$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:
new BladeCompiler( $app['files'], $app['config']['view.compiled'], $app['config']->get('view.relative_hash', false) ? $app->basePath() : '', $app['config']->get('view.cache', true), $app['config']->get('view.compiled_extension', 'php'),);
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:
$name = $request->string('name');// or$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
andstring
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)