Laravel 9.25 Released
Published on by Paul Redmond
The Laravel team released 9.25 with a new string method, mass updating model timestamps with the query builder, and more:
Stringable "when not exactly"
Anjorin Damilare contributed a whenNotExactly
string method that will execute a given callback if the string is not an exact match with the given value:
use Illuminate\Support\Str; // Returns `Iron Man`Str::of('Tony') ->whenNotExactly('Tony Stark', function ($stringable) { return 'Iron Man'; })); // Provide an optional default value if `false`// Returns `Swing and a miss...!`Str::of('Tony Stark') ->whenNotExactly('Tony Stark', function ($stringable) { return 'Iron Man'; }, function ($stringable) { return 'Swing and a miss...!'; }));
Model query touch() method to mass-update timestamps
Steve Bauman contributed a touch()
method to the model query builder, which allows you to touch a model's timestamp with or without query constraints. It behaves like Model::touch()
:
// Mass updating the updated_at columnUser::query()->touch(); // With query constraintsUser::where('email', 'like', '%@company.com')->touch(); // Touching a specific columnPost::query()->touch('published_at');
Release notes
You can see the complete list of new features and updates below and the diff between 9.24.0 and 9.25.0 on GitHub. The following release notes are directly from the changelog:
v9.25.0
Added
- Added whenNotExactly to Stringable (#43700)
- Added ability to Model::query()->touch() to mass update timestamps (#43665)
Fixed
- Prevent error in db/model commands when using unsupported columns (#43635)
- Fixes ensureDependenciesExist runtime error (#43626)
- Null value for auto-cast field caused deprication warning in php 8.1 (#43706)
- db:table command properly handle table who doesn't exist (#43669)