在laravel 5.8中,我使用的是csv文件 https://github.com/Maatwebsite/Laravel-Excel 插件,它可以正常工作,但是当我使用标题方法生成标题时 https://docs.laravel-excel.com/3.1/exports/mapping.html
我需要根据从db获得的结果集设置标题:
<?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
}
}
有这种方法吗?
答案 0 :(得分:2)
您可以使用以下内容:
search