Laravel 6.5 版本發佈功能

LazyCollection

LazyCollection 可以調用 Memy() ,能記取計算過的值,在運算大數據過程,能避免大量消耗內存的狀況。

範例:

<?php ...
$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.

String Helper - afterLast(), beforeLast()

afterLast 可以取得字串中,“最後一個”指定字符 之後的文字

beforeLast 可以取得字串中,“最後一個”指定字符 之前的文字

<?php ...
$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

<?php ...
$user->files()
->where zero('closed_at')
->doesntExistOr(function () {
abort(422, 'User already has an open dossier');
});