chriskelemba/excel-import-laravel

Dynamic CSV/XLSX import package for Laravel with generic table mapping and preview

Maintainers

Package info

github.com/chriskelemba/excel-import-laravel

pkg:composer/chriskelemba/excel-import-laravel

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.3.0 2026-03-09 08:33 UTC

This package is auto-updated.

Last update: 2026-03-09 08:37:47 UTC


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 columns in dynamic-importer.tables.
  • If columns are not configured, importer will infer top-level keys from sample documents.

Endpoints

  • GET /imports/databases?connection=mongodb&table=loans
  • GET /imports/template?table=skills&connection=mysql
  • POST /imports/preview
  • POST /imports/run
  • POST /imports/run-multi

Preview payload

multipart/form-data:

  • file: csv/txt/xlsx
  • table: configured table name
  • connection (optional): Laravel DB connection name (e.g. mysql, mongodb)
  • column_map: map of excel_header => db_column
  • static_values (optional): fixed values applied to every imported row (e.g. ctg_id => 2)
  • header_row (optional, 1-based)
  • sheet_index (optional, default 0)
  • sample_rows (optional)

Run payload

multipart/form-data:

  • file
  • table
  • connection (optional)
  • column_map
  • static_values (optional object)
  • header_row (optional)
  • sheet_index (optional)
  • mode (optional: insert or upsert)
  • unique_by (optional array for upsert)

Multi-table run payload

multipart/form-data:

  • file
  • connection (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_tables for restrictions.