Я использую Laravel 5.8 и maatwebsite / excel 3.1 для экспорта в Excel, но получил ошибку.
Вызов неопределенного метода Maatwebsite \ Excel \ Excel :: create ()
Я написал код экспорта в Controller and View
config / app.php
/*
* Package Service Providers...
*/
Maatwebsite\Excel\ExcelServiceProvider::class,
//Class Aliases
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
Контроллер
use Excel;
public function msisdnExport()
{
$msisdns = User::select(
"phone"
)
->get();
// Initialize the array which will be passed into the Excel
// generator.
$msisdnsArray = [];
// Define the Excel spreadsheet headers
$msisdnsArray[] = ['MSISDN'];
// Convert each member of the returned collection into an array,
// and append it to the payments array.
foreach ($msisdns as $msisdn) {
$msisdnsArray[] = $msisdn->toArray();
}
// Generate and return the spreadsheet
// Excel::create('MSISDN', function($excel) use ($msisdnsArray) {
Excel::download('MSISDN', function($excel) use ($msisdnsArray) {
// Set the spreadsheet title, creator, and description
$excel->setTitle('MSISDN');
$excel->setCreator('Developers')->setCompany('Cloud Africa');
$excel->setDescription('users msisdn file');
// Build the spreadsheet, passing in the payments array
$excel->sheet('sheet1', function($sheet) use ($msisdnsArray) {
$sheet->fromArray($msisdnsArray, null, 'A1', false, false);
});
})->download('xlsx');
}
Просмотр
<a href="{{ route('msisdn-export') }}" class="btn btn-block btn-primary" style="margin-right: 15px;"><i class="fa fa-file-excel-o"></i> Excel</a>
Когда я нажимаю на Excel в представлении, он предполагает экспорт в Excel, но получил эту ошибку.
Вызов неопределенного метода Maatwebsite \ Excel \ Excel :: create ()