chriskelemba / excel-import-laravel
Dynamic CSV/XLSX import package for Laravel with generic table mapping and preview
Package info
github.com/chriskelemba/excel-import-laravel
pkg:composer/chriskelemba/excel-import-laravel
v0.3.0
2026-03-09 08:33 UTC
Requires
- php: ^8.2
- illuminate/database: ^12.0
- illuminate/http: ^12.0
- illuminate/routing: ^12.0
- illuminate/support: ^12.0
Suggests
- mongodb/laravel-mongodb: Required when importing into MongoDB connections.
README
Backend package for dynamic CSV/XLSX preview and import into any configured database table.
Install
composer require chriskelemba/excel-import-laravel
Publish config
php artisan vendor:publish --tag=dynamic-importer-config
Configure (Optional)
config/dynamic-importer.php
'discovery' => [ 'allow_unconfigured_tables' => true, 'allow_tables' => [], // optional allow-list 'exclude_tables' => ['migrations'], ], // Optional strict per-table overrides 'tables' => [ 'skills' => [ 'required' => ['name'], 'unique_by' => ['name'], 'mode' => 'upsert', ], ],
MongoDB Support
Install in your Laravel app:
composer require mongodb/laravel-mongodb
Configure a mongodb connection in config/database.php, then pass connection=mongodb in importer requests.
Notes:
- SQL connections auto-discover table columns/types via schema introspection.
- MongoDB collections are schema-less; prefer defining
columnsindynamic-importer.tables. - If
columnsare not configured, importer will infer top-level keys from sample documents.
Endpoints
GET /imports/databases?connection=mongodb&table=loansGET /imports/template?table=skills&connection=mysqlPOST /imports/previewPOST /imports/runPOST /imports/run-multi
Preview payload
multipart/form-data:
file: csv/txt/xlsxtable: configured table nameconnection(optional): Laravel DB connection name (e.g.mysql,mongodb)column_map: map ofexcel_header => db_columnstatic_values(optional): fixed values applied to every imported row (e.g.ctg_id => 2)header_row(optional, 1-based)sheet_index(optional, default0)sample_rows(optional)
Run payload
multipart/form-data:
filetableconnection(optional)column_mapstatic_values(optional object)header_row(optional)sheet_index(optional)mode(optional:insertorupsert)unique_by(optional array for upsert)
Multi-table run payload
multipart/form-data:
fileconnection(optional global connection)imports[0][table]imports[0][column_map][Loan No]imports[0][column_map][Customer]imports[0][mode]imports[0][unique_by][0]imports[0][static_values][ctg_id](optional fixed value / foreign key)imports[1][table]imports[1][column_map][...]
Database preview
Use GET /imports/databases to drive UI selectors:
connection(optional): selected database connection (mysql,mongodb, ...)table(optional): returns selected table/collection definition including columns
Notes
- CSV support works out of the box.
- XLSX support requires
phpoffice/phpspreadsheet. - XLSX preview grid includes style/merge metadata (
style,rowspan,colspan,skip) when available from reader output. - By default, any existing DB table can be imported (dynamic schema discovery).
- Use
discovery.allow_tables/discovery.exclude_tablesfor restrictions.