To create an empty collection in the Illuminate/Collections package, you can use the collect
function and pass an empty array or simply call the collect
function without any argument. Here are two ways to create an empty collection:
collect
function:$collection = collect([]);
collect
function without any argument:$collection = collect();
Both of these methods will create an empty collection that you can use to add items dynamically.