How to chunk results from a custom query in Laravel
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a custom query that grabs data from the old system and maps it to models in the new system. The query looks like this: $companies = DB::connection('legacy')->select("..."); And since it's a lot of data, I'd like to use Eloquent's chunk feature (just sample code copied from their docs): User::chunk(200, function($users) { foreach ($users as $user) { // } }); How do I implement this? Edit: My code now looks like this, which results in no response: DB::connection('legacy')->select("SELECT * FROM companies")->chunk(200, function(