Laravel团队发布了9.23版本, 增加了artisan docs命令, Vite对CSP/SRI的支持, 一个新的流畅的JSON断言方法等等.让我们来看看最新的Laravel 9版本:
Artisan docs命令
Tim MacDonald贡献了一个新的惊人的artisan docs 命令, 让开发者从命令行中快速访问网站文档:
# Opens a choice dialog you can use to type what you want
php artisan docs
# Opens the validation docs
php artisan docs validation
事情变得非常疯狂, 当, 比方说你想去unique 验证规则的验证文档页面:
php artisan docs validation unique
# partial searches, will open the unique validation rule
php artisan docs va un
下面是一个例子,说明当你不向命令传递页面时的默认行为。

流利的JSON whereNot断言
Mateus Guimarães贡献了一个whereNot() JSON测试断言。
$response
->assertJson(fn (AssertableJson $json) =>
$json->where('id', 1)
->where('name', 'Victoria Faith')
->whereNot('status', 'pending')
->missing('password')
->etc()
);
悄悄地删除一个模型
Anjorin Damilare贡献了一个deleteQuietly() 模型方法,从数据库中删除一个模型而不引发任何事件。
use App\Models\Flight;
$flight = Flight::find(1);
$flight->deleteQuietly();
在文件系统适配器中添加了条件性特质
Ralph J. Smit贡献了为Filesystem添加Conditionable trait,允许你使用when() 和unless() 方法。
Storage::disk('public')
->when(true)
->delete('StardewTaylor.png');
对CSP、SRI和任意值的Vite支持
Tim MacDonald贡献了对Vite实现的第一方支持,以创建一个将用于所有生成的脚本和样式标签的nonce。
use Illuminate\Support\Facades\Vite;
class ContentSecurityPolicy
{
public function handle($request, $next)
{
// You need to call this function **before** resolving the response
// so that 3rd parties can use the same nonce throughout the request
// lifecycle e.g. Ziggy
Vite::useCspNonce();
return $next($response)->withHeaders([
'Content-Security-Policy' => "script-src 'nonce-".Vite::cspNonce()."'",
]);
}
}
发布说明
你可以在GitHub上看到以下完整的新功能和更新列表以及9.22.0和9.23.0之间的差异。下面的发行说明直接来自更新日志。
v9.23.0
新增
- 为Fluent JSON测试匹配器添加了whereNot方法(#43383)
- 为Model添加了deleteQuietly方法,并为相关方法使用箭头函数(#43447)。
- 为文件系统适配器添加了条件性特征(#43450)。
- 引入 artisan docs 命令(#43357)
- 增加了支持CSP nonce、SRI和Vite的任意属性(#43442)。
- 支持从目标对象获取条件的条件器(#43449)
- 添加
whereIn到Illuminate/Routing/RouteRegistrar::allowedAttributes(#43509)
修复了
- 当大量工作被安排在特定时间时,防止redis崩溃(#43310)