+8613426109659
webmaster@21cto.com

Laravel framework 12.42.0 发布

图片

Laravel 团队最新发布了 Laravel framework 12.42 版本,新增了 HTTP 客户端请求属性、Translator 替换中的枚举支持、模式构建器索引方法等功能。

HTTP 客户端请求属性


开发者Luke Kuzmish贡献了一个withAttributes()用于定义实例属性数据的方法PendingRequest

之后,我们就可以使用该attributes()方法检索这些数据。如下实例:

$response =Http::withAttributes(['name'=>'first'])->get('https://example.com/test'); $response->attributes(); // ['name' => 'first']

翻译器替换中对枚举的支持


Hossein Hosni贡献了一个更新,该更新支持在 Translator 替换中使用枚举方式:

$t =newTranslator($loader'en');$t->get('string_backed_enum', ['month'=>Month::February]);// Laravel 12 was released in :month 2025// Laravel 12 was released in February 2025

模式构建器索引检查


Jack Bayliss贡献了whenTableHasIndex基于whenTableDoesntHaveIndex表是否具有索引来运行代码的方法:


use Illuminate\Support\Facades\Schema; // Beforepublicfunctionup():void{if (!Schema::hasIndex('product''name')) {Schema::table('product', function (Blueprint $table) {            $table->index('name''index_name');        });    }} // Afterpublicfunctionup():void{Schema::whenTableHasIndex('product''name', function (Blueprint $table) {        $table->index('name''index_name');    }); // You can also pass the index type...Schema::whenTableDoesntHaveIndex('product''name', function (Blueprint $table) {        $table->index('name''index_name');    },  'unique');}


发行说明


Laravel framework v12.42.0 的主要更新内容汇总如下:

  • [12.x] 改进 Context::scope() 返回类型 #58012
  • [12.x] 允许 CarbonInterval 的 duration 辅助函数中使用浮点值 #58006
  • 将 whenTableHasIndex 和 whenTableDoesntHaveIndex 添加到 Builder 中 #58005
  • [12.x] 添加 commandFileFinder 方法,并从命令发现中排除测试文件 #58017
  • 遵循 queue:work 命令中的 --quiet 和 --silent 参数 #58024
  • [12.x] 添加对容器的依赖项支持 #58026
  • 修复 tests/Support/SupportStringableTest.php 中 StringableObjectStub 类的自动加载问题 #58030
  • [12.x] 移除对 optional() 的调用 #58027
  • [12.x] 添加 newRequest() 到 Pool 和 Batch #58038
  • [12.x] 调整监听器文档块并为查询形状添加单元测试 #58040
  • [12.x] feat::在并行测试中设置数据库时添加 pre-migration hook #58011
  • [12.x] 支持 PHPUnit 12.5 #58042
  • [12.x] 添加对 Translator replacements 中枚举的支持 #58048
  • [12.x] 修复 PendingRequest@pool() && batch() 并发问题 #57973
  • 统一队列命令选项描述规范   #58058
  • [12.x] 为 illuminate/reflection 添加 LICENSE 文件、PR 自动关闭功能及.gitattributes 配置 #58055
  • [12.x] PendingRequest@withRequestContext()#58054

详情可查看更新说明:

https://github.com/laravel/framework/releases/tag/v12.42.0

评论

我要赞赏作者

请扫描二维码,使用微信支付哦。