How can i use the Laravel Maatwebsite Import Export Module in Pyro CMS
Created 7 years ago by srinivas214We have a requirement to implement Import Export Excel, CSV Feature in Pyro CMS. But we couldn't find addon for this requirement. Is there any possibility to integrate the laravel excel module (http://www.maatwebsite.nl/laravel-excel/docs/import) in Pyro CMS? Please share the documents/information if there are any ways to intergrate in Pyro CMS.
You should be able to install it exactly like you would with Laravel. Install and add any service providers to app.php
since that's committed to your project.
Thanks @ryanthompson. I was able to install it. But couldn't inject into the controller function. Please give me solution/ share some reference document to integrate the below codes in to the Admin controller action in Pyro CMS.
ExcelFile class
This class is a wrapper for a file on your server. Inside the getFile() method you return the filename and it's location. Inside the getFilters() method you can enable filters, like the chunk filter.
class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
public function getFile()
{
return storage_path('exports') . '/file.csv';
}
public function getFilters()
{
return [
'chunk'
];
}
}
Usage
You can inject these ExcelFiles inside the __constructor or inside the method (when using Laravel 5.0), in e.g. the controller.
class ExampleController extends Controller {
public function importUserList(UserListImport $import)
{
// get the results
$results = $import->get();
}
}
Thanks! Got the solution
Yes, just install the package through Composer and treat it like a Laravel installation. If you are running the newest version of Pyro, then you should have automatic facade management, so it's really just installing from Composer and following the instructions for an import.
In terms of organization, I handled it like this: I built an extension that handled importing of users on a nightly basis. This extension housed the Excel package (since composer update from the base directory installs composer packages from all addons now) and kept it exclusively in that extension. From there - I just chunked up the import and processed as usual.