Limiting Eloquent chunks
<p>I have a very large result set to process and so I'm using the <code>chunk()</code> method to reduce the memory footprint of the job. However, I only want to process a certain number of total results to prevent the job from running too long.</p>

<p>Currently I'm doing this, but it does not seem like an elegant solution:</p>

<pre><code>$count = 0;
$max = 1000000;
$lists = Lists::whereReady(true);

$lists-&gt;chunk(1000, function (Collection $lists) use (&amp;$count, $max) {
    if ($count &gt;= $max)
        return;

    foreach ($lists as $list) {
        if ($count &gt;= $max)
            break;

        $count++;

        // ...do stuff
    }
});
</code></pre>

<p>Is there a cleaner way to do this?</p>