Laravel 团队最新发布了 Laravel framework 12.42 版本,新增了 HTTP 客户端请求属性、Translator 替换中的枚举支持、模式构建器索引方法等功能。
开发者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
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 的主要更新内容汇总如下:
Context::scope() 返回类型 #58012optional() 的调用 #58027newRequest() 到 Pool 和 Batch #58038PendingRequest@pool() && batch() 并发问题 #57973illuminate/reflection 添加 LICENSE 文件、PR 自动关闭功能及.gitattributes 配置 #58055PendingRequest@withRequestContext()#58054详情可查看更新说明:
https://github.com/laravel/framework/releases/tag/v12.42.0
本篇文章为 @ 行动的大雄 创作并授权 21CTO 发布,未经许可,请勿转载。
内容授权事宜请您联系 webmaster@21cto.com或关注 21CTO 公众号。
该文观点仅代表作者本人,21CTO 平台仅提供信息存储空间服务。
请扫描二维码,使用微信支付哦。