I am using the Laravel Excel project to export data to an Excel file. I am able to generate a file with the correct data using hard coded month and year values, like so
public function month() {
Excel::create('New file', function($excel) {
$excel->sheet('New sheet', function($sheet) {
$data = new ReportModel;
$year = (int)2016;
$month = (int)9;
$donationData = $data->getDayData($month, $year);
$sheet->loadView('exports.month', array('donationData' => $donationData));
});
})->download('xlsx');
}
However, when I try to make the month and year variables, using the following code
public function month($month, $year) {
Excel::create('New file', function($excel) {
$excel->sheet('New sheet', function($sheet) {
$data = new ReportModel;
$year = (int)$year;
$month = (int)$month;
$donationData = $data->getDayData($month, $year);
$sheet->loadView('exports.month', array('donationData' => $donationData));
});
})->download('xlsx');
}
I get the following error
Access to undeclared static property: App\Http\Controllers\ExportController::$year
I understand this is down to variable scope, but can't get my head round the PHP docs. I have tried
$year = (int)self::$year;
but am getting the same result.