首页    新闻    小组    威客    人才    下载    博客    代码贴    在线编程    论坛
Laravel 6.5 发布,新增 5 种新方法
2019年11月10日 21:05 | 阅读 748 次

Laravel 6.5 已经发布,内容如下:

LazyCollection 的新方法

引入了一个新方法,该方法调用 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

Query Builder 新方法

查询生成器(用于创建和运行数据库查询的接口),此版本已经做了更新,增加了 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

(文/开源中国)    




评论 (0)
游客请输入验证码
最新评论
0
0
收藏