My program produces this error but I don't know why. I'm still getting this error, even though I have added the service provider and alias in config/app.php
Call to undefined method Maatwebsite\Excel\Facades\Excel::download()
UserController.php
use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;
class UserController extends Controller
{
private $excel;
public function __construct(Excel $excel)
{
$this->excel = $excel;
}
public function export()
{
return $this->excel->download(new UsersExport, 'users.xlsx');
}
}
UsersExport.php
<?php
namespace App\Exports;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use Modules\User\Entities\User;
class UsersExport implements FromView, ShouldAutoSize, WithEvents
{
use Exportable;
private $fileName = "user.xlsx";
/**
* @return View
*/
public function view(): View
{
return view('users::admin.export', [
'users' => User::all()
]);
}
/**
* @return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->getDelegate()->setRightToLeft(true);
},
];
}
}
Verify again that you have added the service provider and alias in config/app.php
Then try running:
php artisan config:clear
php artisan config:cache