Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

When using Maatwebsite\Excel in laravel project getting Could not open file "" for writing error

I want to generate an excel sheet with custom array in laraval. So I have used "Maatwebsite\Excel" package.
Below is my export function,

public function export(){
    $users = [
        [
            'id' => 1,
            'name' => 'Hardik',
            'email' => 'hardik@gmail.com'
        ],
        [
            'id' => 2,
            'name' => 'Vimal',
            'email' => 'vimal@gmail.com'
        ],
        [
            'id' => 3,
            'name' => 'Harshad',
            'email' => 'harshad@gmail.com'
        ]
    ];
      
    return Excel::download(new RequestExport($users), 'users.xlsx');
}

Here is my RequestExport class,

<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;

class RequestExport implements FromCollection
{
    protected $data;
  
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function __construct($data)
    {
        $this->data = $data;
    }
  
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function collection()
    {
        return collect($this->data);
    }
  
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function headings() :array
    {
        return [
            'ID',
            'Name',
            'Email',
        ];
    }
}

When calling the export function always getting this error,
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Someone please help me to solve this.

>Solution :

Try with clearing cache by php artisan optimize:clear and php artisan config:cache

Also you can recheck you have import Excel:class in files.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading