public function build($collection, array $fields, $config = [])
    {
        $this->config = $config;
        $csv = $this->writer;
        $headers = [];

        foreach ($fields as $key => $field) {
            $headers[] = $field;

            if (!is_numeric($key)) {
                $fields[$key] = $key;
            }
        }

        if (is_a($collection, EloquentCollection::class)) {
            $this->isEloquentCollection = true;
        }

        $this->addHeader($csv, $headers);
        $this->addCsvRows($collection, $fields, $csv);

        return $this;
    }
public function build($collection, array $fields, $config = [])
    {
        $this->config = $config;
        $csv = $this->writer;
        $headers = [];

        foreach ($fields as $key => $field) {
            $headers[] = $field;

            if (!is_numeric($key)) {
                $fields[$key] = $key;
            }
        }

        if (is_a($collection, EloquentCollection::class)) {
            $this->isEloquentCollection = true;
        }

        $this->addHeader($csv, $headers);
        $this->addCsvRows($collection, $fields, $csv);

        return $this;
    }
public function build ( $ collection , array $ fields , $ config = [ ] ) { $ this -> config = $ config ; $ csv = $ this -> writer ; $ headers = [ ] ; foreach ( $ fields as $ key => $ field ) { $ headers [ ] = $ field ; if ( ! is_numeric ( $ key ) ) { $ fields [ $ key ] = $ key ; } } if ( is_a ( $ collection , EloquentCollection :: class ) ) { $ this -> isEloquentCollection = true ; } $ this -> addHeader ( $ csv , $ headers ) ; $ this -> addCsvRows ( $ collection , $ fields , $ csv ) ; return $ this ; }
Build the writer.

@param \Illuminate\Support\Collection $collection
@param array $fields
@param array $config
@return $this
@throws \League\Csv\CannotInsertRecord
Build the writer .