侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Laravel 11.2版本发布- 新增Fluent Helper助手处理多维数组

Laravel  /  管理员 发布于 1年前   329

本周,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

  • 上一条:
    Laravel 11.1版本发布-数据库查询中的非后备枚举、withSchedule()引导方法
    下一条:
    在Laravel中使用PDF Optimizer包轻松优化PDF
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • Laravel 11.14版本发布 - 新的字符串助手和ServeCommand改进(0个评论)
    • Laravel 11.12版本发布 - Artisan的`make`命令自动剪切`.php `扩展(0个评论)
    • Laravel的轻量型购物车扩展包:binafy/laravel-cart(0个评论)
    • Laravel 11.11版本发布 - 查看模型中的第三方关系:show(0个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-07
    • 2017-08
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2020-10
    • 2020-11
    • 2021-01
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客