What's wrong with laravel excel3.0 's "download collection as Excel"?

business is a collection of query results of two tables, which is exported to Laravel Excel , which almost monopolizes the market in excel,. The result document is so concise that I can"t find an api, suitable for my business. I chose a recent "download collection as Excel", the code is:

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/25
 * Time: 11:30
 */

namespace App\Support\excel;


use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;

class FormExport implements FromCollection
{
    private $aid;

    public function __construct()
    {
//        $this->aid = $aid;

    }


    /**
     * @return Builder
     */
    /*    public function query()
        {
            // TODO: Implement query() method.

            $ids [] = "45";
            $ids [] = "46";
            $ids [] = "47";
            $ids[] = "48";

    //        return CompValues::query()->whereIn("id", $ids);
        }*/

    /**
     * @return Collection
     */
    public function collection()
    {

        return (new Collection([[1, 2, 3], [1, 2, 3]]))->downloadExcel("aa.xlsx", $writerType = "Xlsx", $headings = false);
        // TODO: Implement collection() method.
    }
}

error is:


Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::each()

Screenshot:

clipboard.png

ask the boss for advice, and forget it if you answer with 2.0 code.


take a look at the documentation and do not download or use any extra methods in the collection method. You can return a Collection object in the collection method. That is,

public function collection()
{

    return (new Collection([[1, 2, 3], [1, 2, 3]]));
}

then call more of his methods on the controller

public function export(Excel $excel, YourClass $export) 
{
    return $excel->download($export, 'invoices.xlsx');
}

version is downgraded with 2.0

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4307e-434dc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4307e-434dc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?