dan-delvo / excel-import-for-backpack
A Backpack CRUD operation for importing Excel and CSV files with header-to-column mapping.
Package info
github.com/Dan-Delvo/excel-import-for-backpack
pkg:composer/dan-delvo/excel-import-for-backpack
Requires
- ext-zip: *
- backpack/crud: ^7.0
- illuminate/support: ^10.0|^11.0|^12.0
- maatwebsite/excel: ^3.1
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
ExcelImportForBackpack adds an import operation to Backpack for Laravel CRUD controllers.
It provides:
- an Import button on the List operation;
- an import screen that reads Excel or CSV headers in the browser;
- automatic header-to-database-column mapping;
- server-side import handling using
maatwebsite/excel.
Screenshots
Screenshots can be added later. The package is fully usable without published assets.
Installation
Prerequisites:
- PHP ZIP extension enabled (
ext-zip) - A Backpack v7 compatible Laravel application
composer require dan-delvo/excel-import-for-backpack
The package uses Laravel auto-discovery, so no manual service provider registration is required.
If Composer reports that ext-zip is missing, enable the ZIP extension in your CLI PHP installation and run the command again.
If you want to customize the package views or config, publish them with:
php artisan vendor:publish --tag=excel-import-for-backpack
Usage
Add the import operation trait to your CRUD controller:
<?php namespace App\Http\Controllers\Admin; use App\Models\Product; use Backpack\CRUD\app\Http\Controllers\CrudController; use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD; use DanDelvo\ExcelImportForBackpack\Http\Controllers\Operations\ImportOperations; class ProductCrudController extends CrudController { use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation; use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; use ImportOperations; public function setup() { CRUD::setModel(Product::class); CRUD::setRoute(config('backpack.base.route_prefix').'/product'); CRUD::setEntityNameStrings('product', 'products'); } }
Once the trait is added, the package will:
- register
GET /admin/{entity}/importandPOST /admin/{entity}/importroutes; - add an Import button to the List operation;
- render the import screen from the package views.
The import expects the first row of the file to contain headings.
Queue Behavior
The import class implements ShouldQueue and WithChunkReading.
- If your application queue driver is
sync, the import runs immediately. - If your application uses a real queue connection, make sure a queue worker is running.
Overwriting
Publish the package resources:
php artisan vendor:publish --tag=excel-import-for-backpack-views php artisan vendor:publish --tag=excel-import-for-backpack-config
Published views will be placed in:
resources/views/vendor/dan-delvo/excel-import-for-backpack
You can then modify the published Blade files without changing the package source.
Change log
Changes are documented here on Github. Please see the Releases tab.
Testing
composer test
Contributing
Please see contributing.md for a todolist and howtos.
Security
If you discover any security related issues, please email dandelvo12345@gmail.com instead of using the issue tracker.
Credits
License
This project was released under MIT, so you can install it on top of any Backpack & Laravel project. Please see the license file for more information.
However, please note that you do need Backpack installed, so you need to also abide by its YUMMY License. That means in production you'll need a Backpack license code. You can get a free one for non-commercial use (or a paid one for commercial use) on backpackforlaravel.com.