Skip to content

Instantly share code, notes, and snippets.

@craigcabrey
Created August 1, 2015 06:35
Show Gist options
  • Save craigcabrey/5f4bd1979bbce844d833 to your computer and use it in GitHub Desktop.
Save craigcabrey/5f4bd1979bbce844d833 to your computer and use it in GitHub Desktop.
Chunking in laravel
<?php
namespace App\Http\Controllers;
use App\Potato;
class DummyController extends Controller
{
// /dummy/potatoes
public function getPotatoes()
{
$potatoStats = [];
Potato::chunk(10, function($potatoes) use($potatoStats) {
foreach($potatoes as $potato) {
$potatoStats[$potato->created_at]++;
}
});
return response()->json($potatoStats);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment