Laravel - Collections - Method Splitin

The splitIn method breaks a collection into the given number of groups, filling non-terminal groups completely before allocating the remainder to the final group:

    
    $collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
    
    $groups = $collection->splitIn(3);
    
    $groups->all();
    
    // [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]