Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AbdulBazith's avatar

Problem in export option using maatwebsite/laravel

Guys I have installed the package maatwebsite for my project to make an export to excel and pdf. My laravel version is 5.6 After installing I used these coding for my project

controller


    public function downloadExcel($type)
{


        $data = Sales_details::get()->toArray();
        return Excel::load($data, function($excel) use ($data) {
            $excel->sheet('mySheet', function($sheet) use ($data)
            {
                $sheet->fromArray($data);
            });
        })->download($type);


}



But when I click the button it shows an error



Call to undefined method Maatwebsite\Excel\Excel::load()

I refferd in net and found that it is version problem maatwebsite version 2 only supports load() function Maatwebsite version 3 supports store() function.

So I changed load() to store() now it show the error


Type error: Argument 2 passed to Maatwebsite\Excel\Excel::store() must be of the type string, object given, called in D:\XAMPP\htdocs\Laravel\milkfarm\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 221

Whats the mistake kindly suggest. Is the sytax I right else where can I get the new version syntax for Maatwebsite version 3

kindly suggest any related videos or links please

0 likes
3 replies
mattsplat's avatar

Are you using Maatwebsite\Excel\Facades\Excel ?

1 like
AbdulBazith's avatar

@mattsplat yes here is my code in config->app.php file

'aliases' =>
'Excel' => Maatwebsite\Excel\Facades\Excel::class,


and providers

Maatwebsite\Excel\ExcelServiceProvider::class,

and alsoo included

use Maatwebsite\Excel\Facades\Excel;

in my controller

When i googled it say version problem. But all the videos which i referred in youtube using create() and load() function, because they are following version 2 of Maatwebsite

1 like
AbdulBazith's avatar
AbdulBazith
OP
Best Answer
Level 5

@version is the only reason for this problem..

So better use "maatwebsite/excel": "~2.1.0" version

if we simply give

composer require  maatwebsite/excel

it download the latest version 3

so directly give it

"maatwebsite/excel": "~2.1.0"

like this in your composer.json and update the composer.json file

there may some other solution. but i rectified and solved my problem is by doing like this

Refer: https://itsolutionstuff.com/post/laravel-5-import-export-to-excel-and-csv-using-maatwebsite-exampleexample.html

1 like

Please or to participate in this conversation.