title: How can I get the return value of a Laravel chunk?
body: <p>Here's an over-simplified example that doesn't work for me. How (using this method, I know there are better ways if I were actually wanting this specific result), can I get the total number of users?</p>
  
  <pre><code>User::chunk(200, function($users)
  {
     return count($users);
  });
  </code></pre>
  
  <p>This returns NULL. Any idea how I can get a return value from the chunk function?</p>
  
  <p>Edit:</p>
  
  <p>Here might be a better example:</p>
  
  <pre><code>$processed_users = DB::table('users')-&gt;chunk(200, function($users)
  {
     // Do something with this batch of users. Now I'd like to keep track of how many I processed. Perhaps this is a background command that runs on a scheduled task.
     $processed_users = count($users);
     return $processed_users;
  });
  echo $processed_users; // returns null
  </code></pre>