Created
August 1, 2015 06:35
-
-
Save craigcabrey/5f4bd1979bbce844d833 to your computer and use it in GitHub Desktop.
Chunking in laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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