generate an excel with laravel

0

I am trying to generate an excel, from database, using the Maatwebsite library in laravel and it generates "sometimes". It gives me an error: ErrorException (E_NOTICE) Undefined offset: 0

but not with all the tables in the database; with some works, with others not. The code is simple:

class MiExcel implements FromCollection, WithStrictNullComparison,  WithHeadings
{
    use Exportable;

    public function headings(): array
    {
        return [
            '#',
            'Usuario',
        ];
    }

    public function collection()
    { 
        return User::all();   
    }
}



class MiExcelController extends Controller
{

    public function export() 
    {
        return Excel::download(new MiExcel , 'personas.xlsx');
    }
}

I think the problem has to do with index 0 but I can not solve it.

Thanks in advance for the help

    
asked by Gema 07.06.2018 в 23:28
source

0 answers