Laravel-excel: how to pass out of variable to Excel class?

Created on 19 May 2014  路  2Comments  路  Source: Maatwebsite/Laravel-Excel

i want to pass any variable to Excel:: like this

$data = array(
              array('No', 'Name', 'Sex', 'Date of Birth', 'Salary'),
              array('1', 'Theara', 'Male', '21-05-1982', 100),
              array('2', 'Theara', 'Male', '21-05-1982', 100),
           );
Excel::create('Filename', function($excel) {
    $excel->sheet('Sheetname', function($sheet) {
        $sheet->with($data);
    });
})->export('xls');

Most helpful comment

Just like you would with PHP: use($data)

Excel::create('Filename', function($excel) use($data) {

});

All 2 comments

Just like you would with PHP: use($data)

Excel::create('Filename', function($excel) use($data) {

});

Define instance/class variable in that class and assign $data to that variable before Excel::Create and use that class variable inside Excel::create . it works!

Was this page helpful?
0 / 5 - 0 ratings