Laravel团队发布了9.25版本增加了一个新的字符串方法

92 阅读2分钟

Laravel团队发布了9.25版本,增加了一个新的字符串方法,用查询生成器大规模更新模型时间戳,以及更多。

可串联的 "不完全时"

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() 方法,它允许你在有或没有查询约束的情况下触摸一个模型的时间戳。它的行为与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');

发布说明

你可以在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)