Laravel 6.5 發布,新增 5 種新方法

←手機掃碼閱讀     admin @ 2019-11-10 , reply:0

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





[admin ]

來源:OsChina
連結:https://www.oschina.net/news/111202/laravel-6-5-released
Laravel 6.5 發布,新增 5 種新方法已經有22次圍觀

http://coctec.com/news/all/show-post-219075.html