Laravel 团队发布了 9.25 版本,该版本增加了一个新的字符串方法,用查询生成器批量更新模型的时间戳等。

新的字符串方法:whenNotExactly

Anjorin Damilare 贡献了一个字符串方法:whenNotExactly,如果字符串与给定值不完全匹配,将执行给定的回调。

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...!';
    }));

模型查询的touch()方法可以批量更新时间戳

Steve Bauman为模型查询生成器贡献了一个 touch() 方法,它允许批量更新时间戳。

//批量更新updated_at
User::query()->touch()。
 
//根据查询约束更新
User::where('email', 'like', '%@company.com')->touch();
 
//更新一个特定的列
Post::query()->touch('published_at')。

发布说明

你可以在下面看到新功能和更新的完整列表,以及GitHub上9.24.0和9.25.0之间的差异。下面的发行说明直接来自更新日志。

v9.25.0

新增

  • 为Stringable添加了whenNotExactly (#43700)。
  • 增加了Model::query()->touch()批量更新时间戳的能力(#43665)。

修复

  • 防止在使用不支持的列时db/model命令出错(#43635)。
  • 修复 ensureDependenciesExist 运行时错误 (#43626)
  • 在php 8.1中,auto-cast字段的空值会导致破坏性警告(#43706)
  • db:table 命令正确处理不存在的表 (#43669)

变更

  • 在db命令中处理assoc模式(#43636)。
  • 允许在数组和模型上使用chunkById (#43666)
  • 允许whereMonth()和whereDay()使用int值参数 (#43668)
  • 清理旧的if-else语句 (#43712)
  • 确保对css资产使用正确的 “完整性 “值 (#43714)
(adsbygoogle = window.adsbygoogle || []).push({});