Laravel团队发布了9.10版本的findOr()Eloquent方法, 一个新的命令断言, 检索输入为一个Stringable实例, 以及更多。
在刷新数据库功能之前
Rok Sprogar为RefreshDatabase 特质贡献了一个beforeRefreshingDatabase 。这允许你在数据库开始刷新之前运行代码。
class DataExportTest extends TestCase
{
use RefreshDatabase;
protected $seed = true;
protected function beforeRefreshingDatabase()
{
$this->artisan('db:wipe --database another-database-connection');
}
// ...
}
不期望输出命令断言
Markus Hebenstreit贡献了一个doesntExpectOutputToContain 命令断言方法,这是不言自明的。
Artisan::command('contains', function () {
$this->line('My name is Taylor Otwell');
});
$this->artisan('contains')
->doesntExpectOutputToContain('Taylor Otwell');
优雅的 "findOr "方法
Jess Archer为Eloquent builder和关系贡献了一个findOr() 方法。这个方法与现有的firstOr() 方法相匹配。
User::findOr(1, fn () => throw new RuntimeException);
User::findOr(1, fn () => abort(403));
User::findOr(1, fn () => 'return something');
User::findOr(1, ['columns'], fn () => '...');
// Also works with relations
$user->posts()->findOr(1, fn () => '...');
可定制的编译扩展
Taylor Otwell贡献了一个可配置的编译视图扩展,当传入刀片编译器时,可通过view 配置进行定制。
new BladeCompiler(
$app['files'],
$app['config']['view.compiled'],
$app['config']->get('view.relative_hash', false) ? $app->basePath() : '',
$app['config']->get('view.cache', true),
$app['config']->get('view.compiled_extension', 'php'),
);
支持 "IS "和 "IS NOT "PostgreSQL 操作符
Markus Koch贡献了对使用 PostgreSQL 时is 和is not 操作符的支持。详情见第 42123 号拉动请求。
从请求中获取可串联的输入信息
Cameron Wilby和Taylor Otwell贡献了从请求中检索输入的能力,作为一个Stringable 实例。
$name = $request->string('name');
// or
$name = $request->str('name');
添加和预置工作到现有的链上
Jan-Oliver Pantel贡献了prependToChain() 和appendToChain 方法来追加和预置作业。
这方面的用例是,当一个链中的作业想要[原文如此]将作业排到它自己的链上,而不需要创建一个新的链并等待 "子链 "的成功执行。
这在技术上已经可以实现,因为所有需要的属性和方法都是公开的。然而,有了正式的函数,就有了一个更好的DX。
发布说明
你可以在GitHub上看到以下完整的新功能和更新列表以及9.9.0和9.10.0之间的差异。下面的发布说明直接来自于更新日志。
v9.10.0
新增
- 增加了通过MySQL执行upload时使用别名的功能(#42053)。
- Illuminate/Routing/Router::middlewareGroup()将支持中间件的数组(#42004,e6b84fb)。
- 在schedule:list上增加了缺失的AsCommand属性(#42069)。
- 在Testing/RefreshDatabase trait中增加beforeRefreshingDatabase函数(#42073)
- 添加了doesntExpectOutputToContain断言方法(#42096)
- 为Eloquent添加了findOr方法(#42092)
- 允许在
Illuminate/View/Compilers/Compiler.php中进行扩展(68e41fd) - 支持'IS'和'IS NOT'PostgreSQL操作符(#42123)
- 为Illuminate/Http/Concerns/InteractsWithInput添加了
str和string方法 (c9d34b7) - 增加了向现有链添加和预置作业的方法(#42138)
修复问题
- 使不存在的作业沿着失败的路径运行,而不是崩溃(#42079)
- 修复 schedule:work 命令 Artisan 二进制名称(#42083)
- 修复非UTF8字符的TrimStrings中间件(#42065)
- 在Request::createFrom()中复制原始请求的locale和defaultLocale(#42080)
- 修复JSON会话序列化的ViewErrorBag(#42090)
- 修复CompiledRouteCollection::getRoutesByMethod()中来自缓存路由的数组键(#42078)
- 修复JsonResponse::setData的json_last_error问题(#42125)
- 修复BelongsToMany中非相关行被返回的问题(#42087)
- 修复HasAttributes::mutateAttributeForArray访问非缓存属性时的问题(#42130)