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:
ask the boss for advice, and forget it if you answer with 2.0 code.