Laravel 9.16版本发布

2023-06-01 00:00:00 laravel 版本 发布

Laravel 团队发布了9.16,其中包含额外的UUID测试助手、新的Eloquent方法、Pusher的用户身份验证等:


UUID 测试助手

Tim MacDonald 通过 Str 帮助器为 UUID 的生成贡献了额外的 UUID 测试帮助器。 

目前,您可能会首先捕获 UUID 或伪造特定的 UUID,如下所示:

$uuid = Str::uuid();
Str::createUuidsUsing(fn () => $uuid);
 
Str::uuid() === Str::uuid() === $uuid;
 
// Cleanup
Str::createUuidsNormally();

现在有了这个 PR,你可以做以下事情:

Str::freezeUuids();
 
// do stuff...
 
Str::uuid() === Str::uuid() == $uuid;
 
// cleanup...
Str:: createUuidsNormally();

您还可以传递一个闭包以仅在闭包期间冻结创建:

Str::freezeUuids(function ($uuid) {
    // do stuff...
    Str::uuid() === Str::uuid() === $uuid;
});

您还可以返回一系列 UUID:

Str::createUuidsUsingSequence([
    $zeroth = Str::uuid(),
    $first = Str::uuid(),
]);
 
Str::uuid() === $zeroth;
Str::uuid() === $first;
Str::uuid(); // back to random UUIDs

如果您想了解更多信息并查看实施细节,请查看 Pull Request #42619。

https://github.com/laravel/framework/pull/42619


Eloquent withWhereHas()

@eusonlito 提供了一个 withWhereHas() 方法,

它简化了您必须重复使用 whereHas 过滤和通过 with() 选择相同记录的代码的情况:

CollectionModel::whereHas('products', function ($query) {
    $query->where('enabled', true)->where('sale', true);
})->with(['products' => function ($query) {
    $query->where('enabled', true)->where('sale', true);
});

使用 withWhereHas 方法,您可以围绕此用例简化代码:

CollectionModel::withWhereHas(
'products',fn ($query) => $query->where('enabled', true)->where('sale', true)
);

Pusher 的用户认证

@rennokki 为 Pusher 贡献了用户身份验证:

->Pusher 最近推出了一项功能,允许其用户启用连接身份验证以及通道授权:
https://pusher.com/docs/channels/using_channels/user-authentication/

->简而言之,该功能将确保连接到 websockets 的任何人都应该是应用程序中经过身份验证的用户。 
这将增加您已连接用户的信任,并且您可以通过用户的数据库 ID 而不是通常的 Socket ID 向用户的连接广播事件。

有关围绕此功能的讨论和实施的更多详细信息,请参阅 Pull Request #42531。 

https://github.com/laravel/framework/pull/42531

此外,文档拉取请求在发布时打开,其中包含有关如何使用此功能的更多信息。

https://github.com/laravel/docs/pull/7965


发行说明

您可以在下面查看新功能和更新的完整列表以及 GitHub 上 9.15.0 和 9.16.0 之间的差异。 

以下发行说明直接来自变更日志:

https://github.com/laravel/framework/compare/v9.15.0...v9.16.0
https://github.com/laravel/framework/blob/e30bdf08bc604d79f5013733078ce84597663c4d/CHANGELOG.md#v9160---2022-06-02


v9.16.0

添加

添加了 Eloquent withWhereHas 方法 (#42597)
Pusher 的用户身份验证 (#42531)
添加了额外的 uuid 测试助手 (#42619)

修复

修复可排队通知的 ID 被覆盖 (#42581)
处理路由中未定义的数组键错误 (#42606)

已弃用

照亮/路由/重定向器::home() (#42600)


转:

https://laravel-news.com/laravel-9-16-0

相关文章