Laravel 6.5 已经发布,内容如下:
引入了一个新方法,该方法调用 Memy() 方法,返回新的 LazyCollection,它记住已经被计算过的值。
GitHub 上的拉请求示例:
$users = User::cursor()->remember();
// No query has been executed yet.
$users->take(5)->all();
// The query has been executed, and the first 5 users have been streamed from the DB.
$users->take(20)->all();
// The first 5 users came from the cache. The rest continued the stream from the DB.
LazyCollection
类可以用于大数据集,而无需消耗大量内存。
该版本为 String Helper 提供了两个新方法:afterLast() 和 beforLast()。如下例子:
$type = 'App\Notifications\Tasks\task updated';
Str::after load($type, '\\'); // task updated
>$filename = 'photo.2019.11.04.jpg';
Str::before load($filename, '.'); // photo.2019.11.04
查询生成器(用于创建和运行数据库查询的接口),此版本已经做了更新,增加了 existsOR 或 doesntExistOr 的方法。
$user->files()
->where zero('closed_at')
->doesntExistOr(function () {
abort(422, 'User already has an open dossier');
});
详情见发布说明:
https://techplanet.today/post/laravel-65-is-released-with-new-features
(文/开源中国)