Laravel 10.40版本发布 - 加入数字夹方法、APA 风格助手、Vite 资产路径自定义等功能
Laravel  /  管理员 发布于 1年前   253
Laravel 团队发布了 v10.40,其中包括数字夹方法、APA 风格标题大小写字符串助手、
Vite 资产路径自定义等。距离 Laravel 11 发布还有不到一个月的时间,
社区正在全速前进,每周都会发布新功能、修复和改进。
以下是本周发布的部分新特性:
添加数字钳位方法
James Brooks 提供了一个 Number::clamp() 方法,可将给定的数字夹在两个数字之间。
这提供了一种在其他两个数字之间限制给定数字的方法。
这种方法最好用一些示例来说明:
Number::clamp(number: 53, min:0, max: 999); // 53
Number::clamp(number: 0.5, min: 0, max: 1); // 0.5
Number::clamp(number: 20, min: 0, max: 1); // 1
Number::clamp(number: 10, min: 20, max: 30); // 20
添加会话 "except "方法
Volodya Kurshudyan 提供了一个 except() 方法,
用于检索除指定项目数组之外的所有会话数据:
Session::all(); // 'email' => '[email protected]', 'name' => 'Example User']
Session::except(['name']); // ['email' => '[email protected]']
模式生成器可宏化
Kevin Bui 为模式生成器添加了 Macroable 特性,使开发人员能够为模式生成器定义自定义方法。
下面是拉取请求的作者提供的示例:
use Illuminate\Database\Schema\Builder;
Builder::macro('hasForeignKey', function ($table, $key) {
$foreignKeys = Schema::getForeignKeys($table);
foreach ($foreignKeys as $foreignKey) {
if ($foreignKey['name'] == $key) {
return true;
}
}
return false;
});
空视图的测试断言
Dwight Watson 为 TestView 类提供了 assertViewEmpty() 方法。
现在,您可以如下断言视图组件的输出是否为空:
$view = $this->view('welcome', ['name' => 'Example User', 'enabled' => false]);
$view->assertViewEmpty();
为尾风分页添加暗模式支持
Sabin Chacko 为 simple-paginate.blade.php 和 tailwind.blade.php 文件贡献了暗模式支持。
详情请参见 Pull Request #49515。
允许自定义 Vite 资产路径
蒂姆-麦克唐纳(Tim MacDonald)贡献了在更高级的情况下自定义 Vite 资产路径的能力,
在这种情况下您不能依赖于 app.asset_url 的静态值,在服务提供商中使用以下方法:
Vite::createAssetPathsUsing(function ($path, $secure) {
return //...
});
使用 QueueFake 断言作业数量
Volodya Kurshudyan 为 QueueFake 贡献了 assertCount() 断言
use Illuminate\Support\Facades\Queue;
Queue::fake();
Queue::assertNothingPushed();
// ...act...
Queue::assertCount(3);
APA 风格标题字符串助手
Adam Campbell 提供了一个 APA 风格的标题助手,可根据 APA 标题大小写指南格式化字符串:
https://github.com/hotmeteor
https://apastyle.apa.org/style-grammar-guidelines/capitalization/title-case
Str::apa($string);
str($string)->apa();
发布说明
您可以在 GitHub 上查看以下新功能和更新的完整列表以及 10.39.0 和 10.40.0 之间的差异。
以下版本说明直接来自更新日志:
https://github.com/laravel/framework/compare/v10.39.0...v10.40.0
https://github.com/laravel/framework/blob/8f48538ed651173d4dcb3ee42c9c90453adc5869/CHANGELOG.md#v10400---2024-01-09
v10.40.0
[10.x] 模型::preventAccessingMissingAttributes() 会为
@cosmastech 在 https://github.com/laravel/framework/pull/49480 中未检索到的枚举和原始可铸造属性引发异常。
[10.x] 通过 @hafezdivandari
在 https://github.com/laravel/framework/pull/49509 为 MariaDB 纳入系统版本控制表
[10.x] 修正 Arr::dot() 方法以正确处理索引数组,
作者:@kayw-geek 发布于 https://github.com/laravel/framework/pull/49507
[10.x] 扩展 Gate::allows & Gate::denies 签名。
作者 @antonkomarev 发布于 https://github.com/laravel/framework/pull/49503
[10.x] 改进数字比较以实现自定义投射
(由 @imahmood 在 https://github.com/laravel/framework/pull/49504 提供
[10.x] 添加会话 except 方法
(由 @xurshudyan 在 https://github.com/laravel/framework/pull/49520 中提供
[10.x] 添加 Number::clamp
作者:@jbrooksuk 发布于 https://github.com/laravel/framework/pull/49512
[10.x] 修正 Schedule 测试
@michaelnabil230 发布于 https://github.com/laravel/framework/pull/49538
[10.x] 使用正确的日期格式
@buismaarten 发布于 https://github.com/laravel/framework/pull/49541
[10.x] 清理 Arr 由
@michaelnabil230 在 https://github.com/laravel/framework/pull/49530 提供
[10.x] 使 ComponentAttributeBag 可数组化
by @iamgergo in https://github.com/laravel/framework/pull/49524
[10.x] 修复未指定默认值时的 whenAggregated 问题
(由 @lovePizza 在 https://github.com/laravel/framework/pull/49521 提供
[10.x] 更新 AsArrayObject.php 以使用 ARRAY_AS_PROPS 标志
(由 @pintend 在 https://github.com/laravel/framework/pull/49534 提供
[10.x] 删除 @tillkruss 在 https://github.com/laravel/framework/pull/49560
中提出的无效 RedisCluster::client() 调用。
[10.x] 删除 PhpRedisConnector 中未使用的代码
@tillkruss 发布于 https://github.com/laravel/framework/pull/49559
[10.x] 在测试运行期间刷新有关命令(Flush about command)
(作者:@timacdonald,发表于 https://github.com/laravel/framework/pull/49557
[10.x] 修复parentOfParameter方法,
作者:@iamgergo,地址:https://github.com/laravel/framework/pull/49548
[10.x] 让模式生成器可以宏化
@kevinb1989 发表于 https://github.com/laravel/framework/pull/49547
[10.x] 删除测试中未使用的代码
@imahmood 发表于 https://github.com/laravel/framework/pull/49566
[10.x] 更新查询/生成器.php $columns typehint
by @Grldk in https://github.com/laravel/framework/pull/49563
[10.x] 在 TestView 中添加 assertViewEmpty
作者 @dwightwatson 发布于 https://github.com/laravel/framework/pull/49558
[10.x] 更新 tailwind.blade.php 以适应黑暗模式
by @sabinchacko03 in https://github.com/laravel/framework/pull/49515
[10.x] 修复缓存 FileStore 中空值的弃用问题
by @driesvints in https://github.com/laravel/framework/pull/49578
[10.x] 允许自定义 Vite 资产路径
(由 @timacdonald 在 https://github.com/laravel/framework/pull/49437 提供
[10.x] 对 Illuminate\Database\Query\Builder
中与日期和时间相关的 where*() 方法的第二个参数进行类型提示
(由 @lorenzolosa 在 https://github.com/laravel/framework/pull/49599 提供
[10.x] 修复 Stringable::convertCase() 返回类型
(由 @vaites 在 https://github.com/laravel/framework/pull/49590 提供
允许在本地 Iterables 上调用 \Blade::stringable()
by @tsjason in https://github.com/laravel/framework/pull/49591
[10.x] 使用 InteractsWithTime 特质方法重构时间处理
(由 @xurshudyan 在 https://github.com/laravel/framework/pull/49601 提供
[10.x] 添加 assertCount 测试助手,
作者 @xurshudyan 发布于 https://github.com/laravel/framework/pull/49609
[10.x] @deleugpn 在 https://github.com/laravel/framework/pull/49527
中提出的在不使用配置库的情况下建立连接的功能
[10.x] 添加 APA 风格标题助手
(由 @hotmeteor 提供,载于 https://github.com/laravel/framework/pull/49572
[10.x] 修正错误输出中替代选项的用法
@Mrjavaci 发表于 https://github.com/laravel/framework/pull/49614
[10.x] 为 PlanetScale 的 MySQL 兼容 Vitess 19 引擎的队列作业弹出使用锁
(由 @crynobone 在 https://github.com/laravel/framework/pull/49561 提供
转:
https://laravel-news.com/laravel-10-40-0
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号