Laravel 9.47 发布啦!更新速览~

本篇文章给大家带来了关于laravel9.47的最新消息,其中主要介绍了laravel 团队近期发布的9.47版本都有哪些新功能,感兴趣的朋友一起来看一下吧,希望对大家有帮助。

Laravel 9.47 发布啦!更新速览~

Laravel 团队近期发布了 9.47,其中包含新的 Eloquent 集合可见性方法、「可销毁的」单例路由、支持带有 batch fake 的懒加载集合等等:

新的 Eloquent 集合可见性方法

Jess Archer 为 Eloquent 集合贡献了 setVisible 和 setHidden 方法。 当你想明确要返回的数据时,setVisible 方法很有用,并且它不会在向模型添加新属性时泄漏:

$users->setVisible(['id', 'name'])->toArray(); /* [     [         'id' => 1,         'name' => 'Test User',     ] ] */

如果你只有几个要显式隐藏的字段,但通常希望默认值可见,则相反的 setHidden 很有用。

在 BatchFake 中支持懒加载集合

Jess Archer 在将 withFakeBatch() 与作业一起使用时贡献了对 LazyCollection 的支持。 由于此功能,现在可以使用以下功能:

use Batchable;  Model::cursor()     ->map(fn (Model $model) => new ModelJob($model))     ->chunk(1000)     ->each(function (LazyCollection $jobs) {         $this->batch->add($jobs);     });  // 相关测试 [$job] = (new ModelJobBatch())->withFakeBatch();  $job->handle();

 了解更多关于模拟批处理的信息,请点击Jess Archer.

“可销毁的”单例路由

Jess Archer 贡献了一个简单的方法,将单例路由标记为”可销毁”。这种类型的路由可以被删除,但默认不会被创建。

// 以前 Route::singleton(...)->creatable()->except('create', 'store');  // 之后 Route::singleton(...)->destroyable();

发布说明

你可以在github上看到以下完整的新功能和更新列表以及 Jess Archer 之间的差异。下面的发行说明直接来自 Jess Archer

v9.47.0

新增

  • 在 BatchFake::add() 中添加了支持懒加载集合 (Jess Archer)
  • 添加小数到数字规则列表(Jess Archer)
  • 添加 Illuminate/Routing/PendingSingletonResourceRegistration::destroyable() 可销毁路由 (Jess Archer)
  • 将 setVisible 和 setHidden 添加到 Eloquent 集合 (Jess Archer)

修复

修改

推荐学习:《Jess Archer


原文地址:Jess Archer

译文地址:Jess Archer

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享