giving me error of
Declaration of Handler is not compatible with \ExxportHandler
i'm following your instruction on how to decouple excel-code completely from my controllers but it is giving me error.. on my end i fix this by removing the dependency injection Export Class of my export handler to make it an anonymous like what the interface says that cause the error. . if you have a quick fix for these please let me know . .
thankss for the great work
Can you please show me your code.
I just copy and paste the following codes on this documentation here
UserListExport
`
class UserListExport extends \Maatwebsite\Excel\Files\NewExcelFile {
public function getFilename()
{
return 'filename';
}
}
`
UserListExportHandler
`
class UserListExportHandler implements \Maatwebsite\Excel\Files\ExportHandler {
public function handle(UserListExport $export)
{
// work on the export
return $export->sheet('sheetName', function($sheet)
{
})->export('xls');
}
}
`
now to try it
Route::get('/test', function(\App\UserListExport $export) {
$export->handleExport();
});
as expected i'm still getting the error Declaration of App\UserListExportHandler::handle() must be compatible with Maatwebsite\Excel\Files\ExportHandler::handle()
but if i remove the UserListExport in UserListExportHandler@handler like this public function handle($export) and it's working fine
@patrickbrouwers The problem is the Maatwebsite\Excel\Files\ExportHandler::handle($file) interface method that is not type hinting the file class, while the implementation example in the docs does.
@rzb Your'e right, just remove the type in the handle method and it works :)
Most helpful comment
@patrickbrouwers The problem is the
Maatwebsite\Excel\Files\ExportHandler::handle($file)interface method that is not type hinting the file class, while the implementation example in the docs does.