Laravel0Laravel 9.25 Released | Laravel News

[ad_1]

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 column

User::query()->touch();

 

// With query constraints

User::where('email', 'like', '%@company.com')->touch();

 

// Touching a specific column

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

[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *