【发布时间】:2018-09-22 15:47:29
【问题描述】:
我是 Laravel 的新手,但我使用 laravel 的 Maatwebsite\Excel Library v3 来导出 excel。但是我在导出数组数据时遇到了一些问题。
这是我的代码
<?php
namespace App\Exports;
use App\Team;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithHeadings;
class RegisteredMemberExport implements FromCollection, WithHeadings
{
use Exportable;
public function collection()
{
$data = Team::where('reg', 1)->get();
return collect([
[
'name' => $data->name,
'email' => $data->email
]
]);
}
public function headings(): array
{
return [
'name',
'email'
];
}
}
收集应该是
return collect
([
[
'name' => 'Povilas',
'email' => 'povilas@laraveldaily.com'
],
[
'name' => 'Taylor',
'email' => 'taylor@laravel.com'
]
]);
我不能在 collect 方法返回中使用循环。 我可以帮忙吗?
【问题讨论】:
-
你想从coolection得到什么数据
-
你想用循环做什么?