您好,我正在尝试下载excel格式的数据库数据,,,但是当我单击下载时,它显示:调用未定义的方法Maatwebsite\Excel\Excel::create()
控制器代码:
function excel()
{
$pdf_data = DB::table('importpdfs')->get()->toArray();
$pdf_array[] = array('Battery', 'No_of_questions_attempted', 'SAS', 'NPR', 'ST', 'GR');
foreach($pdf_data as $pdf)
{
$pdf_array[] = array(
'Battery' => $pdf->Battery,
'No_of_questions_attempted' => $pdf->No_of_questions_attempted,
'SAS' => $pdf->SAS,
'NPR' => $pdf->NPR,
'ST' => $pdf->ST,
'GR' => $pdf->GR
);
}
Excel::create('Pdf Data', function($excel) use ($pdf_array){
$excel->setTitle('Pdf Data');
$excel->sheet('Pdf Data', function($sheet) use ($pdf_array){
$sheet->fromArray($pdf_array, null, 'A1', false, false);
});
})->download('xlsx');
}发布于 2019-06-19 19:28:02
从laravel-excel版本3.0中删除了create方法。
Excel Excel::create()被移除并替换为
::download/Excel::store($yourExport)
我会使用他们文档中的quickstart guide。
发布于 2019-06-19 19:29:22
如果您之前将"maatwebsite/excel"包更新为3.*。版本,则删除方法Excel::create($yourExport)。相反,您应该使用Excel::download/Excel::store($yourExport)。
示例如何在新版本中使用它:
use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;
class UsersController extends Controller
{
public function export()
{
return Excel::download(new UsersExport, 'users.xlsx');
}
}其中,UsersExport是使用make:export命令创建的新类。
UsersExport.php:
<?php
namespace App\Exports;
use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
class UsersExport implements FromCollection
{
public function collection()
{
return User::all();
}
}在这里你可以找到一个新版本的官方Upgrade guide。
发布于 2019-06-19 19:27:03
您可能没有使用Facade并直接使用文件,请确保您正在使用
use Maatwebsite\Excel\Facades\Excel;而不是
use Maatwebsite\Excel\Excel;https://stackoverflow.com/questions/56666430
复制相似问题