private function addCsvRows(Collection $collection, array $fields, Writer $csv)
    {
        if ($this->isEloquentCollection) {
            $collection->makeVisible($fields);
        }

        foreach ($collection as $model) {
            $beforeEachCallback = $this->beforeEachCallback;
            // Call hook
            if ($beforeEachCallback) {
                $return = $beforeEachCallback($model);
                if ($return === false) {
                    continue;
                }
            }

            if (! $this->isEloquentCollection) {
                $model = collect($model);
            }
            $model->toArray();

            $csvRow = [];
            foreach ($fields as $field) {
                $csvRow[] = Arr::get($model, $field);
            }

            $csv->insertOne($csvRow);
        }
    }
private function addCsvRows(Collection $collection, array $fields, Writer $csv)
    {
        if ($this->isEloquentCollection) {
            $collection->makeVisible($fields);
        }

        foreach ($collection as $model) {
            $beforeEachCallback = $this->beforeEachCallback;
            // Call hook
            if ($beforeEachCallback) {
                $return = $beforeEachCallback($model);
                if ($return === false) {
                    continue;
                }
            }

            if (! $this->isEloquentCollection) {
                $model = collect($model);
            }
            $model->toArray();

            $csvRow = [];
            foreach ($fields as $field) {
                $csvRow[] = Arr::get($model, $field);
            }

            $csv->insertOne($csvRow);
        }
    }
private function addCsvRows ( Collection $ collection , array $ fields , Writer $ csv ) { if ( $ this -> isEloquentCollection ) { $ collection -> makeVisible ( $ fields ) ; } foreach ( $ collection as $ model ) { $ beforeEachCallback = $ this -> beforeEachCallback ; // Call hook if ( $ beforeEachCallback ) { $ return = $ beforeEachCallback ( $ model ) ; if ( $ return === false ) { continue ; } } if ( ! $ this -> isEloquentCollection ) { $ model = collect ( $ model ) ; } $ model -> toArray ( ) ; $ csvRow = [ ] ; foreach ( $ fields as $ field ) { $ csvRow [ ] = Arr :: get ( $ model , $ field ) ; } $ csv -> insertOne ( $ csvRow ) ; } }
Add rows to the CSV.

@param \Illuminate\Support\Collection $collection
@param array $fields
@param \League\Csv\Writer $csv
@return void
@throws \League\Csv\CannotInsertRecord
Add rows to the CSV .