Laravel 10.46版本发布-自定义金额递增速率限制器
Laravel  /  管理员 发布于 1年前   316
Laravel团队本周发布了v10.46,带来了新的枚举(Enum)验证方法、按自定义金额递增费率限制器、
可条件枚举验证规则等:
#枚举验证获得 only() 和 except() 方法
@Anton5360 为枚举验证规则贡献了两个新方法,
当您不希望所有枚举情况都有效时,这两个方法就会生效:
Rule::enum(ServerStatus::class)
->only([ServerStatus::Pending, ServerStatus::Active]);
Rule::enum(ServerStatus::class)
->except([ServerStatus::New]);
状态枚举就是这些方法实用性的一个很好的例子:
当记录状态从 "新建 "转为 "已发送 "后,您可能不希望记录再次回到该状态。
拉取请求描述中的另一个例子是,一旦货物状态为已发货,就只允许已送达、已取消或已拒收。
#费率限制器可按自定义金额递增
Sebastien Armand 提供了按自定义金额递增费率限制值的功能:
有时,速率限制并不能直接映射为每次增加 1。
例如
带宽使用限制
对批量调用更新次数的限制,每次调用可能意味着多次 "命中
对某些操作所用时间的限制
下面举例说明如何使用 increment() 方法按自定义金额增加总数:
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::increment('send-message:'.$user->id, amount: 5);
有关详情,请参阅文档中的手动增加尝试次数。
https://laravel.com/docs/10.x/rate-limiting#manually-incrementing-attempts
为枚举规则添加 #Conditionable
Michael Nabil 提供了在 Rule::enum() 验证规则中使用 Conditionable 特性的功能:
Rule::enum(PostStatus::class)
->when(
auth()->user()->is_admin,
fn ($rule) => $rule->only([PostStatus::APPROVED]),
fn ($rule) => $rule->only([PostStatus::PADDING]),
);
发布说明
您可以在 GitHub 上查看以下新功能和更新的完整列表,以及 10.45.0 和 10.46.0 之间的差异。
以下发布说明直接来自更新日志:
https://github.com/laravel/framework/compare/v10.45.0...v10.46.0
https://github.com/laravel/framework/blob/eb66928b4aaa3fa84bdd95db44d27fc7e0977563/CHANGELOG.md#v10460---2024-02-27
v10.46.0
[10.x]由 @nuernbergerA 在 https://github.com/laravel/framework/pull/50176 中
提出的[10.x]确保懒加载垃圾 morphTo 关系的工作原理
[10.x] 当 $keys 为字符串时 Arr::select 无法工作
by @Sicklou in https://github.com/laravel/framework/pull/50169
[10.x] 添加了将加载的关系传递到值回调的功能,
作者 @dkulyk 发布于 https://github.com/laravel/framework/pull/50167
[10.x] 修复创建数据库时可选择的字符集和校对方式
(由 @GrahamCampbell 在 https://github.com/laravel/framework/pull/50168 提供
[10.x] 更新 PendingProcess.php 中的文档块
by @saMahmoudzadeh in https://github.com/laravel/framework/pull/50198
[10.x] 在可批处理特质中修复接受可空参数、更新 doc 块和空指针异常处理,
作者 @saMahmoudzadeh 发布于 https://github.com/laravel/framework/pull/50209
使 GuardsAttributes 的可填充属性 DocBlock 更具体
(由 @liamduckett 在 https://github.com/laravel/framework/pull/50229 提供
[10.x] 在枚举验证规则中添加 only 和 except 方法,
作者 @Anton5360 发布于 https://github.com/laravel/framework/pull/50226
[10.x] 修复在应用作用域时执行嵌套操作的问题。
作者:@Guilhem-DELAITRE 发布于 https://github.com/laravel/framework/pull/50207
[10.x] 增加自定义速率限制器(RateLimiter),
作者:@khepin,发布于 https://github.com/laravel/framework/pull/50197
[10.x] 在查询生成器中添加侧向连接(Lateral Join)
by @Bakke in https://github.com/laravel/framework/pull/50050
[10.x] 更新返回类型
by @AmirRezaM75 in https://github.com/laravel/framework/pull/50252
[10.x] 修复 dockblock
作者 @michaelnabil230 发布于 https://github.com/laravel/framework/pull/50259
[10.x] 在枚举规则中添加 Conditionable
by @michaelnabil230 in https://github.com/laravel/framework/pull/50257
[10.x] 将 Facade::$app 更新为 nullable
by @villfa in https://github.com/laravel/framework/pull/50260
[10.x] 截断带前缀的 sqlite 表名
(由 @kitloong 在 https://github.com/laravel/framework/pull/50251 提供
Str::orderedUuid() 的更正注释 - https://github.com/larave...
by @wq9578 in https://github.com/laravel/framework/pull/50268
转:
https://laravel-news.com/laravel-10-46-0
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号