1

I am trying to do an export of custom data which gets fed into DataTables in userfrosting. I have loaded the maatwebsite excel library using composer and the autoload_classmap.php was updated. In the controller I tried using the following:

Excel::create('master',function($excel) use($events){                    
    $excel->sheet('Master List', function($sheet) use($events){          
        $sheet->fromArray($events);                                      
    });                                                                  
})->export('xls'); 

When I run this, I get the following error:

PHP Fatal error:  Class 'UserFrosting\Excel' not found in /usr/www

I have looked at the laravel examples and tried them and they work with no problems. But I need this to work on userfrosting as the application is already and only missing the export.

JoeM
  • 21
  • 7

2 Answers2

1

This sounds like a namespace issue. Try:

\Maatwebsite\Excel\Excel::create(...

Note that I've used the fully qualified namespace for the Excel class.

alexw
  • 8,468
  • 6
  • 54
  • 86
  • Hi @alexw , thanks for the response, I am still getting the same result `Class 'Maatwebsite\Excel' not found` when I implement `use \Maatwebsite\Excel\Files\NewExcelFile as Excel;` I am starting to feel like I might not know what I am doing here. – JoeM Jul 15 '16 at 10:02
  • Can you post the full set of changes that you've made to your controller file? – alexw Jul 15 '16 at 16:39
  • My code `namespace UserFrosting; use \Maatwebsite\Excel\Files\NewExcelFile as Excel; class MyController extends \UserFrosting\BaseController { public function pageMaster() { $events = Events::get(); Excel::create('master',function($excel) use($events){ $excel->sheet('Master List', function($sheet) use($events){ $sheet->fromArray($events); }); })->export('xls'); } } ` – JoeM Jul 18 '16 at 09:04
  • Also, I just updated my answer. Get rid of your `use` statement, and just try my code with the fully qualified path. – alexw Jul 18 '16 at 14:26
  • I have crated the gist with the new error I am encountering here: https://gist.github.com/TheMainJoe/ad7271ce3cd9822c1e4667a390eab09b – JoeM Jul 19 '16 at 09:16
  • Perhaps we should continue this discussion in [chat](https://chat.userfrosting.com/). – alexw Jul 19 '16 at 13:54
1

I ended up leaving maatwebsite/excel for phpoffice/phpexcel which worked a bit quicker for me, I will attempt to get an answer to this question in the near future.

JoeM
  • 21
  • 7
  • Thanks for the update! You saved my day. Kindly update this page info, if you were able to have maatwebsite/excel running in UF and if you found it more useful than phpexcel. Thanks! – Spurgeon Sep 12 '16 at 10:00
  • Hi, please see feedback I received from the maatwebsite forum, they say they only assist if you have issues on laravel as it is its main support. https://github.com/Maatwebsite/Laravel-Excel/issues/866 – JoeM Sep 19 '16 at 21:32