Laravel 9.2版本发布

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

Laravel 团队发布了 9.2.0 版本,

其中包含一个数组 keyBy 方法、一个 Eloquent 属性静态构造函数、将 Laravel CORS 包移动到框架中,等等:


属性制作方法

@ARI 为 Eloquent Attribute 类贡献了一个静态构造方法,提供了如下便利:

// Using the new keyword
return (new Attribute(
    get: fn ($value) => strtoupper($value),
    set: fn ($value) => strtoupper($value)
))->withoutObjectCaching();
 
// The new make() static constructor method
return Attribute::make(
    get: fn ($value) => strtoupper($value),
    set: fn ($value) => strtoupper($value)
)->withoutObjectCaching();


数组 keyBy 方法

Douglas Medeiros 贡献了一个 Arr::keyBy() 方法,其工作方式类似于集合 keyBy() 方法:

$array = [
    ['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
    ['id' => '345', 'data' => 'def', 'device' => 'tablet'],
    ['id' => '345', 'data' => 'hgi', 'device' => 'smartphone'],
];
 
Arr::keyBy($array, 'id');
/*
[
    '123' => ['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
    '345' => ['id' => '345', 'data' => 'hgi', 'device' => 'smartphone']
    // The second element of an original array is overwritten by the last element because of the same id
]
*/


期望输出包含测试断言

Francisco Madeira 贡献了一个 expectsOutputToContain 测试方法来断言 artisan 命令包含输出的子字符串:

$this->artisan('Hello World')->expectsOutputToContain('Hello');


使用 Mail::alwaysTo 时添加 X 标头

Craig Morris 在使用 Mail::alwaysTo() 方法时贡献了在开发中添加 X 标头:

>When using Mail::alwaysTo in development environments, the original To, Cc and Bcc are lost. This makes it difficult to determine where the email was going to during testing.

This PR adds the original to, cc and bcc into X-Headers in the email so this information can be retrieved, while still preventing the email being sent to these recipients.

这对于调试预期收件人、抄送和密件抄送字段很有用,但仅将电子邮件发送到指定的 alwaysTo 地址。 

查看 Pull Request #41101 了解详情。


将 Laravel CORS 集成到框架中

Dries Vints 将 fruitcake/laravel-cors 包迁移到 Laravel 框架中:


>The main reason is that we want to remove a circular dependency we rely on additionally to the fact that we eliminate another dependency of the skeleton.

All credits for the code go to @barryvdh of @fruitcake . Thanks for maintaining that package for so long!


String "Between First" 方法

Yoeri Boven 贡献了一个 betweenFirst() 方法,它获取两个给定值之间的字符串的最小可能部分:

Str::betweenFirst('[a]ab[b]', '[', ']'); // a
Str::betweenFirst('foofoobar', 'foo', 'bar'); // foo
Str::betweenFirst('hannah', 'ha', 'ah'); // nn
Str::betweenFirst('dddabcddd', 'a', 'c')); // b


允许为规则对象指定自定义消息

Ryan Chandler 提供了一种在使用 Rule 对象进行验证时指定自定义错误消息的方法。 

通过此更新,您可以向消息数组提供自定义消息:

$request->validate(
    [
        'foo' => [new Example]
    ],
    [
        Example::class => 'My custom message goes here!'
    ]
);


发行说明

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

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


v9.2.0

新增的

添加了 Illuminate/Database/Eloquent/Casts/Attribute::make() (#41014)
添加了 Illuminate/Collections/Arr::keyBy() (#41029)
将 expectsOutputToContain 添加到 PendingCommand。 (#40984)
添加了使用 JsonSerializable 实例提供 HTTP 客户端方法的功能 (#41055)
添加了 Illuminate/Filesystem/AwsS3V3Adapter::getClinet() (#41079)
在 Builder::whereRelation (#41091) 中添加了对枚举的支持
使用 Mail::alwaysTo 时添加了 X 标头 (#41101)
在查询中添加支持按位运算符 (#41112)
将 Laravel CORS 集成到框架中 (#41137)
添加了 Illuminate/Support/Str::betweenFirst() (#41144)
允许为 Rule 对象指定自定义消息 (#41145)

修复的

修复了 Queue Failed_jobs 插入问题,异常包含 UNICODE (#41020)
修复尝试在模拟上记录弃用 (#41057)
修复 loadAggregate 未正确应用强制转换 (#41050)
不要在 HTTP 客户端方法中将 JsonSerializable 实例转换为数组 (#41077)
修复解析 config('database.connections.pgsql.search_path') (#41088)
Eloquent: firstWhere 返回 Object 而不是 NULL (#41099)
使用提供的合格 updated_at 修复更新 (#41133)
修复 MailChannel 的 setPriority 调用 (#41120)
修复 route:list 命令输出 (#41177)
修复数据库迁移 $connection 属性 (#41161)

修改的

光标分页:将原始列转换为表达式 (#41003)
在 Paginator 上将 $perPage 转换为整数 (#41073)
恢复 S3 客户端额外选项 (#41097)
在 Illuminate/Notifications/HasDatabaseNotifications.php 中的 notifications() 中使用 latest() (#41095)
删除重复查询以查找批次 (#41121)
删除 FormRequest::validated() 中的冗余检查 (#41115)
Illuminate/Support/Facades/Storage::fake() 已更改 (#41113)
使用 PHP >= 7.4 (#41174) 提供的合并相等
使用 is_countable() 简化一些条件 (#41168)
将 AWS 临时 URL 选项传递给 createPresignedRequest 方法 (#41156)
让 Multiple* 异常保存找到的记录和项目的数量 (#41164)

更多了解请访问github版本源码说明

https://github.com/laravel/framework/compare/v9.1.0...v9.2.0
https://github.com/laravel/laravel

转:

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

相关文章