Example of Collection Methods: Chunk in Kovah/LinkAce

File app/Console/Commands/UpdateLinkThumbnails.php (link to Github)
use App\Models\Link;
use Illuminate\Console\Command;

class UpdateLinkThumbnails extends Command
{
    //
    public function handle(): void
    {
        //
        Link::where('status', Link::STATUS_OK)->latest()
            ->chunk(100, function ($links) use ($processedLinks, $totalCount) {
                foreach ($links as $link) {
                    $this->updateThumbnailForLink($link);
                    sleep(1); // Rate limiting of outgoing traffic
                }

                $processedLinks += count($links);
                $this->comment("Processed $processedLinks of $totalCount links.");
            });
        //
    }
    //
}