【发布时间】:2019-11-06 06:46:06
【问题描述】:
在 laravel 5.8 生成 csv 文件中我使用 https://github.com/Maatwebsite/Laravel-Excel 插件,它工作正常,但我使用标题方法生成标题 https://docs.laravel-excel.com/3.1/exports/mapping.html
我需要根据从数据库获得的结果集来设置标题:
<?php
namespace App\Exports;
use Auth;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class exportSearchResults implements FromCollection, WithHeadings
{
public function collection()
{
$searchResultRows = SearchResult
::getByUserList($this->user_list_id)
->select( 'source_id' )
->groupBy( 'source_id' )
->orderBy('source_id', 'asc')
->get()
->toArray();
...
return $searchResultRows;
}
public function headings(): array
{
return [
'field',
'value',
];
// I need Somehow to return content of this array based on $searchResultRows array in collection method
}
}
有这样的方法吗?
【问题讨论】:
标签: laravel laravel-5 maatwebsite-excel