Laravel 9.25 Released

Admin   Laravel   698  2022-08-23 03:00:02

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:

1use Illuminate\Support\Str;
2 
3// Returns `Iron Man`
4Str::of('Tony')
5 ->whenNotExactly('Tony Stark', function ($stringable) {
6 return 'Iron Man';
7 }));
8 
9// Provide an optional default value if `false`
10// Returns `Swing and a miss...!`
11Str::of('Tony Stark')
12 ->whenNotExactly('Tony Stark', function ($stringable) {
13 return 'Iron Man';
14 }, function ($stringable) {
15 return 'Swing and a miss...!';
16 }));

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():

1// Mass updating the updated_at column
2User::query()->touch();
3 
4// With query constraints
5User::where('email', 'like', '%@company.com')->touch();
6 
7// Touching a specific column
8Post::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)

Changed

  • Handle assoc mode within db commands (#43636)
  • Allow chunkById on Arrays, as well as Models (#43666)
  • Allow for int value parameters to whereMonth() and whereDay() (#43668)
  • Cleaning up old if-else statement (#43712)
  • Ensure correct 'integrity' value is used for css assets (#43714)

Source: laravel-news.com