Laravel - Collections - Method Collect

The collect method returns a new Collection instance with the items currently in the collection:

    
    $collectionA = collect([1, 2, 3]);
    
    $collectionB = $collectionA->collect();
    
    $collectionB->all();
    
    // [1, 2, 3]
	

The collect method is primarily useful for converting lazy collections into standard Collection instances:

    
    $lazyCollection = LazyCollection::make(function () {
        yield 1;
        yield 2;
        yield 3;
    });
    
    $collection = $lazyCollection->collect();
    
    get_class($collection);
    
    // 'Illuminate\Support\Collection'
    
    $collection->all();
    
    // [1, 2, 3]
	
The collect method is especially useful when you have an instance of Enumerable and need a non-lazy collection instance. Since collect() is part of the Enumerable contract, you can safely use it to get a Collection instance.