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

Laravel 10.33版本发布

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

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

  • 上一条:
    在RabbitMQ种实现批量消费队列数据方法示例
    下一条:
    在php+laravel项目中使用Saloon扩展包编写API集成
  • 昵称:

    邮箱:

    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交流群

    侯体宗的博客