Reputation: 609
hi m trying to download db data in excel format,,, but when I click on download then it says: Call to undefined method Maatwebsite\Excel\Excel::create()
code of controller:
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');
}
Upvotes: 1
Views: 10147
Reputation: 3951
If you previously updated your "maatwebsite/excel"
package to 3.*. version, the method Excel::create($yourExport)
is removed. Instead you should use Excel::download/Excel::store($yourExport)
.
Example how it should be used with new version:
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');
}
}
Where UsersExport
is a new class created by using the make:export
command.
UsersExport.php:
<?php
namespace App\Exports;
use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
class UsersExport implements FromCollection
{
public function collection()
{
return User::all();
}
}
Here you can find official Upgrade guide to a new version.
Upvotes: 1
Reputation: 8242
The create method was removed with laravel-excel
version 3.0
.
From the upgrade guide:
Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)
I would use the quickstart guide from their documentation.
Upvotes: 1
Reputation: 224
You are probably not using the Facade and using the file directly, make sure you are using
use Maatwebsite\Excel\Facades\Excel;
and not
use Maatwebsite\Excel\Excel;
Upvotes: 0