Closed
Description
- Laravel Version: 6.20.34
- PHP Version: 7.4.2
- Database Driver & Version:
mysql 5.7.34-log
Description:
After LazyCollection calls the unique method and then calls the isEmpty method, a piece of data will be lost.
Steps To Reproduce:
// The offending code snippet:
$items = \Illuminate\Support\LazyCollection::make(fn () => yield from [['id' => '1'], ['id' => '2'], ['id' => '4']]);
dump($items->toArray()); // Output: [['id' => '1'], ['id' => '2'], ['id' => '4']]
$unique_items = $items->unique('id');
// If the output is here, there is no problem, but `LazyCollection::isEmpty()` will return true.
// dump($unique_items->toArray()); // Output: [['id' => '1'], ['id' => '2'], ['id' => '4']]
if (!$unique_items->isEmpty()) {
// When I judge whether it is a null value, I lost a value.
dump($unique_items->toArray()); // Output: [['id' => '2'], ['id' => '4']]
}
// Everything is normal for this part of the code.
$items = \Illuminate\Support\Collection::make([['id' => '1'], ['id' => '2'], ['id' => '4']]);
dump($items->toArray());
$items = $items->unique('id');
if (!$items ->isEmpty()) {
dump($items ->toArray());
}