Laravel 9.2版本发布
Laravel  /  管理员 发布于 3年前   998
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
老牛 2022-02-28 10:37:29 赞 (0)
老牛博客已更换为新域名:https://naibawu.com(原为:https://xiaohost.com),麻烦老铁修改下友链,谢谢!
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号