fd22b0bf58
V2 (Laravel re-make)
561 B
561 B
whenEmpty()
The whenEmpty
method will execute the given callback when the collection is empty:
const collection = collect([]);
collection.whenEmpty(c => c.push('Mohamed Salah'));
collection.all();
// ['Mohamed Salah']
const collection = collect(['Sadio Mané']);
collection.whenEmpty(
c => c.push('Mohamed Salah'),
c => c.push('Xherdan Shaqiri'),
);
collection.all();
// [
// 'Sadio Mané',
// 'Xherdan Shaqiri',
// ];