Laravel 10.35 发布
Laravel 发布了 v10.35,包括 Blade @use
指令,数字缩写助手,artisan down
生成 secrect 的能力。以下是关于本周推出的新功能的更多信息:
添加 Blade @use() 指令
Simon Hamp 贡献了 @use()
指令,用于在不使用原生 PHP 标签的情况下引入 Blade 模板:
{{-- 以前 --}}
@php
use \App\Enums\WidgetStatusEnum as Status;
@endphp
{{-- 之后 --}}
@use('App\Enums\WidgetStatusEnum', 'Status')
@use('App\Models\Bar')
{{ Status::Foo }}
{{ Bar::first() }}
使用 Number::abbreviate() 数字
@jcsoriano 贡献了 Number::abbreviate()
类,到新添加的 Number 类中,用于提供人类可读的缩写数字:
Number::abbreviate(1_000_000); // "1M"
Number::abbreviate(100_001); // "100K"
Number::abbreviate(100_100); // "100K"
Number::abbreviate(99_999); // "100K"
Number::abbreviate(99_499); // "99K"
将 --with-secret 选项添加到 artisan down 命令
Jacob Daniel Prunkl 贡献了 --with-secret
选项到 artisan down
命令,这将生成一个可用于绕过维护模式的 secrect 短语,这样用户就不必自己定义:
将条件性 Conditionable
trait 添加到 AssertableJson
类
Khalil Laleh 贡献了将 Conditionable
trait 添加到 AssertableJson
类,使之可以居于给定的条件断言:
// Before
$response->assertJson(function (AssertableJson $json) use ($condition) {
$json->has('data');
if ($condition) {
$json->has('meta');
}
$json->etc();
});
// After
$response
->assertJson(fn (AssertableJson $json) => $json->has('data'))
->when($condition, fn (AssertableJson $json) => $json->has('meta'))
// ...
;
发布说明
你可以在下面看到新功能和更新的完整列表,以及 GitHub 上 10.34.0 和 10.35.0 之间的差异。以下发行说明直接来自更改日志:
v10.35.0
- [10.x] Add Conditionable trait to AssertableJson by @khalilst in https://github.com/laravel/framework/pull/49172
- [10.x] Add --with-secret option to Artisan down command. by @jj15asmr in https://github.com/laravel/framework/pull/49171
- [10.x] Add support for Number::summarize by @jcsoriano in https://github.com/laravel/framework/pull/49197
- [10.x] Add Blade @use directive by @simonhamp in https://github.com/laravel/framework/pull/49179
- [10.x] Fixes retrying failed jobs causes PHP memory exhaustion errors when dealing with thousands of failed jobs by @crynobone in https://github.com/laravel/framework/pull/49186
- [10.x] Add "substituteImplicitBindingsUsing" method to router by @calebporzio in https://github.com/laravel/framework/pull/49200
- [10.x] Cookies Having Independent Partitioned State (CHIPS) by @fabricecw in https://github.com/laravel/framework/pull/48745
- [10.x] Update InteractsWithDictionary.php to use base InvalidArgumentException by @Grldk in https://github.com/laravel/framework/pull/49209
- [10.x] Fix docblock for wasRecentlyCreated by @stancl in https://github.com/laravel/framework/pull/49208
- [10.x] Fix loss of attributes after calling child component by @rojtjo in https://github.com/laravel/framework/pull/49216
- [10.x] Fix typo in PHPDoc comment by @caendesilva in https://github.com/laravel/framework/pull/49234
- [10.x] Determine if the given view exists. by @hafezdivandari in https://github.com/laravel/framework/pull/49231