Laravel - Collections - Method TakeUntilTimeout

The takeUntilTimeout method returns a new lazy collection that will enumerate values until the specified time. After that time, the collection will then stop enumerating:

    $lazyCollection = LazyCollection::times(INF)
    $lazyCollection->each(function ($number) {
    // 1
    // 2
    // ...
    // 58
    // 59

To illustrate the usage of this method, imagine an application that submits invoices from the database using a cursor. You could define a scheduled task that runs every 15 minutes and only processes invoices for a maximum of 14 minutes:

    use App\Models\Invoice;
    use Illuminate\Support\Carbon;
            Carbon::createFromTimestamp(LARAVEL_START)->add(14, 'minutes')
        ->each(fn ($invoice) => $invoice->submit());