I'm using Laravel-Excel library to develop an export xls function.
I need to add a value to specific cell. As documentation, I wrote script
$data = MyModel::getComplexData();
Excel::create('Export payroll', function($excel) use ($data) {
$excel->sheet('Sheet1', function($sheet) use ($data) {
$sheet->cell('A1', function ($cell) use ($data) {
$cell->setValue($data->name);
});
});
})->download('xls');
You can see parameter $data
had been passed 3 times over 3 callback functions.
I need to find a way to make the script more clearly (pass $data
only 1 time).