Laravel 11.2版本发布- 新增Fluent Helper助手处理多维数组
Laravel  /  管理员 发布于 1年前   312
本周,Laravel 团队发布了 v11.2,其中包括 fluent() 支持助手、context() 助手、
改进了迁移操作中丢失数据库的处理等。
Fluent Helper
Philo Hermans在处理多维数组时贡献了一个fluent()辅助函数。
Fluent类在 Laravel 框架中已经存在了相当长的时间;
不过,本次 PR 引入了一个辅助方便方法来创建 Fluent 对象实例:
$data = [
'user' => [
'name' => 'Philo',
'address' => [
'city' => 'Amsterdam',
'country' => 'Netherlands',
]
],
'posts' => [
[
'title' => 'Post 1',
],
[
'title' => 'Post 2',
]
]
];
collect($data)->get('user');
fluent($data)->user;
collect($data)->get('user')['name'];
fluent($data)->get('user.name');
collect(collect($data)->get('posts'))->pluck('title');
fluent($data)->collect('posts')->pluck('title');
json_encode(collect($data)->get('user')['address']);
fluent($data)->scope('user.address')->toJson();
上下文辅助函数
Michael Nabil提供了一个方便的 context()辅助函数,用于管理上下文。
根据传递的参数,您可以添加上下文、获取上下文对象或检索上下文(可选自定义默认值):
// Add user information to the context
context(['user' => auth()->user()]);
// Retrieve the context object
$context = context();
// Retrieve user information from the context
$user = context('user');
// Optional custom default value if not found.
$some_key = context('key_that_does_not_exist', false);
上下文获取器的默认值
Michael Nabil为上下文获取器的默认值提供了支持:
// Before: Returns null if not found
Context::get('is_user');
Context::getHidden('is_user');
// After: Returns `false` if not found
Context::get('is_user', false); // false
Context::getHidden('is_user', false); // false
Context::get('is_user'); // null
作业链测试断言方法
Günther Debrauwer贡献了assertHasChain()和assertDoesntHaveChain()方法:
public function test_job_chains_foo_bar_job(): void
{
$job = new TestJob();
$job->handle();
$job->assertHasChain([
new FooBarJob();
]);
// $job->assertDoesntHaveChain();
}
更好地处理数据库创建/擦除
Dries Vints提供了在数据库尚未创建时运行migrate时更好的数据库故障处理方法(#50836),
并更新了migrate:fresh命令,以简化数据库不存在时的处理流程(# 50838):
"
如果 在尚未创建任何数据库的情况下调用了migrate:fresh 命令,
那么在试图擦除数据库时就会失败。
本程序将解决这个问题,首先检查迁移表是否存在,如果不存在,则跳过 db:wipe 命令,
立即执行迁移命令。
这样就会调用迁移命令流程,随后命令会要求用户创建数据库。
结合 #50836 ,这将为试图通过 Laravel 安装程序安装 Jetstream
并选择不创建数据库的用户提供更无缝的体验。
"
以上描述摘自Pull Request #50838。
https://github.com/laravel/framework/pull/50838
字符串修剪会删除不可见字符
Dasun Tharanga贡献了对框架TrimStrings中间件的更新,
在该更新中,HTTP 请求中的不可见字符不会被修剪,这可能会在提交表单时造成问题。
详情请参见Pull Request #50832。
发布说明
您可以在 GitHub 上查看以下新功能和更新的完整列表以及11.1.0 和 11.2.0的差异。
以下发布说明直接来自更新日志:
https://github.com/laravel/framework/compare/v11.1.0...v11.2.0
https://github.com/laravel/framework/blob/209800f04a1b6012a70c25f9e2164cbe28c9d0ed/CHANGELOG.md#v1120---2024-04-02
v11.2.0
[11.x] 修正:更新某些文档块中的[@param](https://github.com/param)by@saMahmoudzadehinhttps://github.com/laravel/framework/pull/50827
[11.x] 修复:更新某些文档块中的@returnby@saMahmoudzadehinhttps://github.com/laravel/framework/pull/50826
[11.x] 修复在传统 PostgreSQL 上检索生成列的问题,作者:@hafezdivandari,原文地址:https://github.com/laravel/framework/pull/50834
[11.x] 修剪不可见字符@dasundev发布于https://github.com/laravel/framework/pull/50832
[11.x] 为Context上的get和getHidden添加默认值(作者:@michaelnabil230,发表于https://github.com/laravel/framework/pull/50824
[11.x] 改进为Artisan 命令服务的功能@nunomaduro发表于https://github.com/laravel/framework/pull/50821
[11.x]@axlon在https://github.com/laravel/framework/pull/50843中提出的在登录一次时重提用户密码的建议
[11.x] 如果数据库不存在,则不清除数据库 by@driesvintsinhttps://github.com/laravel/framework/pull/50838
[11.x] 更好地处理数据库创建失败 by@driesvintsinhttps://github.com/laravel/framework/pull/50836
[11.x] 在 SQL Server 上使用默认模式名称 by@hafezdivandariinhttps://github.com/laravel/framework/pull/50855
纠正 startedAs 和 virtualAs 数据库列定义的类型@ollieread发布于https://github.com/laravel/framework/pull/50851
允许在多对多关系中将查询表达式作为列传递(由@plumthedev在https://github.com/laravel/framework/pull/50849提供
[11.x] 修正中间件::trustHosts(子域: true)by@axloninhttps://github.com/laravel/framework/pull/50877
[11.x] 修改 getGateArguments 的文档块 by@saMahmoudzadehinhttps://github.com/laravel/framework/pull/50874
[11.x] 在 resolve 方法的文档块中添加[@throws](https://github.com/throws)by@saMahmoudzadehinhttps://github.com/laravel/framework/pull/50873
[11.x] Str trim 方法@patrickomeara发布于https://github.com/laravel/framework/pull/50822
[11.x] 添加流畅助手 by@PhiloNLinhttps://github.com/laravel/framework/pull/50848
[11.x] 添加一个新的上下文帮助程序@michaelnabil230发布于https://github.com/laravel/framework/pull/50878
[11.x] 工作实例上的assertChain和assertNoChain(由@gdebrauwer在https://github.com/laravel/framework/pull/50858提供
[11.x] 移除某些类中多余的getDefaultNamespace方法(类、接口和特质命令),作者@saMahmoudzadeh发布于https://github.com/laravel/framework/pull/50880
[11.x] 移除 MariaDbConnector 中多余的 ConnectorInterface 实现,作者@saMahmoudzadeh,原文地址:https://github.com/laravel/framework/pull/50881
[11.X] 修复:在查询中使用orderByRaw之后再使用cursorPaginate时的错误(由@ngunyimacharia在https://github.com/laravel/framework/pull/50887提供
转:
https://laravel-news.com/laravel-11-2-0
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号