Laravel 10.33版本发布
Laravel  /  管理员 发布于 1年前   247
本周,Laravel 团队发布了 v10.33版本,新增了数字辅助方法、作业链中存在的批次测试断言、
十六进制颜色验证规则等。下面是关于本周发布的新特性的更多信息:
数字工具类
卡恩-德-席尔瓦(Caen De Silva)贡献了 Laravel 数字实用类,它简化了大多数数字格式化需求。
数字助手位于 Illuminate\Support 包中,为你提供了几个新的助手。
下面是几个例子:
Number::format(25) // 25
Number::format(100000) // 100,000
Number::format(123456789) // 123,456,789
Number::format(123456789, 'en') // 123,456,789
Number::format(123456789, 'de') // 123.456.789
Number::format(123456789, 'sv') // 123 456 789
Number::toPercentage(25) // 25%
Number::toPercentage((1/3) * 100, precision: 2) // 33.33%
请参阅我们关于 Laravel Number Utility Class 的文章,了解最新的 Laravel 辅助工具。
对作业链中存在的批次进行断言
Taylor Otwell 通过一个新的 Bus::chainedBatch 测试助手改进了作业链中存在的批次的可测试性。
下面是 Pull Request #49003 中的一个示例:
// Route
Route::get('/batch', function () {
Bus::chain([
new TestJob,
Bus::batch([
new TestJob,
]),
new TestJob,
])->dispatch();
});
// Test
Bus::fake();
$response = $this->get('/batch');
$response->assertSuccessful();
Bus::assertChained([
new TestJob,
Bus::chainedBatch(function ($batch) {
return $batch->jobs->count() === 1;
}),
new TestJob,
]);
更多详情,请参阅新的测试工作链文档。
将 $validator 作为参数传递给基于闭包的规则
@shinsente 通过在基于闭包的验证规则中添加验证器实例作为参数做出了贡献:
use Closure;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\LazyCollection;
use Illuminate\Validation\Validator as ValidationValidator;
$rules = [
'price' => [
function (string $attribute, mixed $value, Closure $fail, ValidationValidator $validator) {
if (!price_logic($value, $validator->attributes()['payment_country'] ?? null)) {
$fail("The {$attribute} is invalid.");
}
},
],
];
添加 color_hex 验证规则
Niko Peikrishvili 贡献了一个 hex_color 验证规则,
其中被验证的字段必须包含以十六进制表示的有效颜色值:
$v = Validator::make(['color' => '#fff'], ['color' => 'hex_color']);
$v->passes(); // true
$v = Validator::make(['color' => '#ggg'], ['color' => 'hex_color']);
$v->passes(); // false
Andy Hinkle 还为十六进制验证规则提供了阿尔法通道支持:
$v = Validator::make(['color' => '#FF000080'], ['color' => 'hex_color']);
$v->passes(); // true
版本说明
您可以在 GitHub 上查看以下新功能和更新的完整列表,以及 10.32.0 和 10.33.0 之间的差异。
以下版本说明直接来自更新日志:
https://github.com/laravel/framework/compare/v10.32.0...v10.33.0
https://github.com/laravel/framework/blob/742f83518e6c427c32b74996b3bc6b789c7128d6/CHANGELOG.md#v10330---2023-11-21
v10.33.0
[10.x] 修正错误的参数传递,并将这些规则添加到依赖规则中
@kayw-geek 发表于 https://github.com/laravel/framework/pull/49008
[10.x] 将 Validator::getValue() 设为公有
by @shinsenter in https://github.com/laravel/framework/pull/49007
[10.x] 为密码验证规则定制信息
@rcknr 发布于 https://github.com/laravel/framework/pull/48928
[10.x] 将数据库播种器控制台输出运行时的毫秒数取整
by @SjorsO in https://github.com/laravel/framework/pull/49014
[10.x] 添加一个 Number 实用程序类,
作者 @caendesilva,原文地址:https://github.com/laravel/framework/pull/48845
[10.x] 修复 DefaultService 类中的 replace() 方法
by @jonagoldman in https://github.com/laravel/framework/pull/49022
[10.x] 将属性 $validator 作为参数传递给 $callback Closure
(由 @shinsenter 在 https://github.com/laravel/framework/pull/49015 提供
[10.x] 修复缓存 DatabaseStore::add() 在 Postgres 事务中发生的错误,
作者 @xdevor 发布于 https://github.com/laravel/framework/pull/49025
[10.x] 支持针对链式批次的断言
(由 @taylorotwell 在 https://github.com/laravel/framework/pull/49003 提供
[10.x] 防止 DB Cache::get() 发生竞赛条件
by @xdevor in https://github.com/laravel/framework/pull/49031
[10.x] 修复通知在没有 "shouldSend "方法的情况下被算作已发送的问题(
由 @joelwmale 发布于 https://github.com/laravel/framework/pull/49030
[10.x] 由 @hafezdivandari 在 https://github.com/laravel/framework/pull/49037
中提出的修复 Windows 上测试失败的问题
[10.x] 在验证规则中添加除非条件
(由 @michaelnabil230 在 https://github.com/laravel/framework/pull/49048 提供
[10.x] 在创建 PSR 请求实例时处理非 JSON 或表单数据的基于字符串的有效载荷
(由 @timacdonald 在 https://github.com/laravel/framework/pull/49047 提供
[10.x] 修复目录分隔符 CMD 在 windows 上的显示问题,
作者 @imanghafoori1,原文地址:https://github.com/laravel/framework/pull/49045
[10.x] 由 @timacdonald 在 https://github.com/laravel/framework/pull/48941
中提出的修复 mapSpread doc 问题
[10.x] Tiny Support\Collection 测试修复 - 未使用的数据提供者参数,
作者:@stevebauman 发布于 https://github.com/laravel/framework/pull/49053
[10.x] 功能: 添加 color_hex 验证规则
(由 @nikopeikrishvili 发布于 https://github.com/laravel/framework/pull/49056
[10.x] 使用回调处理丢失的翻译字符串,
作者 @DeanWunder,原文地址:https://github.com/laravel/framework/pull/49040
[10.x] 为 Stringable 添加 Str::transliterate
by @dwightwatson in https://github.com/laravel/framework/pull/49065
为十六进制验证规则添加 Alpha 通道支持
@ahinkle 发表于 https://github.com/laravel/framework/pull/49069
转:
https://laravel-news.com/laravel-10-33-0
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号