3
  • PHP version: 7.3.9
  • Laravel version: 5.8.30
  • Package version: 3.1

Description

I am trying to export excel file. I do all things in the documentation and the process work with no errors. but the excel file does not download.. I'm using Ubuntu OS.

UserExport.php

<?php

 namespace App\Exports;

 use App\User;
 use Maatwebsite\Excel\Concerns\FromCollection;

 class UsersExport implements FromCollection
 {
    /**
     */
     public function collection()
     {
         return User::all();
      }
  } 

ExportExcelController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Exports\UsersExport;

use Maatwebsite\Excel\Facades\Excel;

class ExportExcelController extends Controller
{
    public function export() 
    {

        return Excel::download(new UsersExport, 'users.xlsx');
    }
}

Tharindu Prabodhana
  • 181
  • 1
  • 4
  • 16

2 Answers2

0

I was seeing the same behavior. I got around it by clearing out all caches and recreating the config cache.

php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan config:cache
  • When you go through setting up the maatwebsite/excel package in your project, it adds some new config under config/excel.php. For me, I was seeing the behavior described in the question above because I had cached a version of the config before the excel config got added. That's why when I cleared the caches and recreated the config cache it fixed the problem for me. You may not be having a problem with the config the way I was. – Jake Killpack Feb 22 '21 at 01:29
0

I was using the package with inertia-vue and using an <a></a> in place of the <Link></Link> tag worked the trick

F KIng
  • 438
  • 4
  • 10