Laravel - Collections - Method Takeuntil

The takeUntil method returns items in the collection until the given callback returns true:

    
    $collection = collect([1, 2, 3, 4]);
    
    $subset = $collection->takeUntil(function ($item) {
        return $item >= 3;
    });
    
    $subset->all();
    
    // [1, 2]
	

You may also pass a simple value to the takeUntil method to get the items until the given value is found:

    
    $collection = collect([1, 2, 3, 4]);
    
    $subset = $collection->takeUntil(3);
    
    $subset->all();
    
    // [1, 2]
	
If the given value is not found or the callback never returns true, the takeUntil method will return all items in the collection.