I want to generate an excel sheet with custom array in laraval. So I have used "Maatwebsite\Excel" package.
Below is my export function,
public function export(){
$users = [
[
'id' => 1,
'name' => 'Hardik',
'email' => 'hardik@gmail.com'
],
[
'id' => 2,
'name' => 'Vimal',
'email' => 'vimal@gmail.com'
],
[
'id' => 3,
'name' => 'Harshad',
'email' => 'harshad@gmail.com'
]
];
return Excel::download(new RequestExport($users), 'users.xlsx');
}
Here is my RequestExport class,
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
class RequestExport implements FromCollection
{
protected $data;
/**
* Write code on Method
*
* @return response()
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Write code on Method
*
* @return response()
*/
public function collection()
{
return collect($this->data);
}
/**
* Write code on Method
*
* @return response()
*/
public function headings() :array
{
return [
'ID',
'Name',
'Email',
];
}
}
When calling the export function always getting this error,
Someone please help me to solve this.
>Solution :
Try with clearing cache by php artisan optimize:clear and php artisan config:cache
Also you can recheck you have import Excel:class in files.