The importer adds the Import files module to the administration. Administrators upload a file, choose its type and the importer class of that type processes the rows. Every step is logged.

Installation

Add the importer section and run php artisan admin:migrate:
config/admin_helpers.php
Other keys of an import are allowed. Read them in your importer.

Importer class

app/Imports/ProductsImport.php
  • Column keys are the headers of the file converted to lower case with underscores, e.g. Product name becomes product_name.
  • format calls isValid{Format}($value, $row) of the importer. Rows with invalid values are listed in the error.
  • cast calls cast{Cast}($value) before the row is returned.
  • Empty cells are null.
  • Override validate(AdminModel $import) for checks of the whole file.

States and logs

Write your own log entries with $import->logReport($type, $code, $message, $log), where $type is info, error or success. Log exceptions with $import->logException($e). The Show logs button of each import shows them.

Custom import model

Extend AdminHelpers\Importer\Models\ImportsFile to change when files can be processed again:
app/Models/Import/ImportsFile.php
Other overridable methods: getImports(), getImporter(), canImport() and canProcess(). The type select of the form renders a ShowSampleImportFile component under the field. Create it in your component directory to offer a sample file.