Illuminate\Database\Eloquent\Builder::chunk PHP Метод

chunk() публичный Метод

Chunk the results of the query.
public chunk ( integer $count, callable $callback ) : boolean
$count integer
$callback callable
Результат boolean
    public function chunk($count, callable $callback)
    {
        $this->enforceOrderBy();
        $page = 1;
        do {
            $results = $this->forPage($page, $count)->get();
            $countResults = $results->count();
            if ($countResults == 0) {
                break;
            }
            // On each chunk result set, we will pass them to the callback and then let the
            // developer take care of everything within the callback, which allows us to
            // keep the memory low for spinning through large result sets for working.
            if (call_user_func($callback, $results) === false) {
                return false;
            }
            $page++;
        } while ($countResults == $count);
        return true;
    }

Usage Example

Пример #1
1
 /**
  * Chunk the results of the query.
  *
  * @param int $count
  * @param callable $callback
  * @return void 
  * @static 
  */
 public static function chunk($count, $callback)
 {
     \Illuminate\Database\Eloquent\Builder::chunk($count, $callback);
 }
All Usage Examples Of Illuminate\Database\Eloquent\Builder::chunk