maatwebsite下载数据库



我使用laravel 8和maatwebsite 3.1,希望通过单击图标下载(导出(我的数据库表作为excel文件。正如我所搜索的,我们必须通过手工php artisan make:export blogExport --model=blog创建一个类,并且在控制器中使用下载方法。CCD_ 2。blogExport包含collection((函数,我们应该在其中确定输出。但我想在控制器中写函数,并直接在这个函数中确定我想要的输出,而不是使用blogExport。有可能吗?有一种方法";CREATE";可以使用,但它是旧的,不支持maatwebsite 3.1。任何回复都将不胜感激。

class ExcellExport implements FromCollection, WithHeadings, WithEvents, WithStrictNullComparison,ShouldAutoSize
{
use Exportable;
public function __construct($header, $query)
{
$this->header = $header;
$this->query = $query;
}
//======================================
public function headings(): array
{
return [$this->header];
}
//======================================
public function collection()
{
return collect($this->query);

}
}

然后像这样传递您的查询:

$query = Estate::where($inputs)->with('landlord', 'rented', 'my_estate_list');
$headers=["code,type_caption,space,landlord,area,address,price"];
$resultExcell = new ExcellExport($headers, $query);
return Excel::download($resultExcell, 'file_name.xlsx');

最新更新