Features

File Formats

Supported file formats and custom reader implementation.

Tapix supports importing data from multiple file formats out of the box. Each format is handled by a dedicated reader class that implements a common interface.

Supported Formats

ExtensionReader ClassUnderlying Library
.csvCsvReaderspatie/simple-excel
.txtCsvReaderspatie/simple-excel
.xlsxXlsxReaderspatie/simple-excel

Both CsvReader and XlsxReader use spatie/simple-excel under the hood, providing reliable and memory-efficient file parsing.

The FileReader Interface

Every reader implements the FileReader interface:

interface FileReader
{
    public function canRead(string $path): bool;

    public function headers(string $path): array;

    public function rows(string $path): iterable;

    public function totalRows(string $path): int;
}
  • canRead() -- Returns true if the reader can handle the given file path.
  • headers() -- Extracts column headers from the first row of the file.
  • rows() -- Returns an iterable of all data rows (excluding the header row).
  • totalRows() -- Returns the total number of data rows in the file.

Reader Configuration

The default reader mapping is defined in the Tapix config file:

config/tapix.php
'readers' => [
    'csv' => CsvReader::class,
    'txt' => CsvReader::class,
    'xlsx' => XlsxReader::class,
],

The FileReaderFactory selects the appropriate reader based on the uploaded file's extension. If no reader is registered for a given extension, an exception is thrown.

Header Detection

Headers are extracted automatically from the first row of the file. Tapix uses these headers during the column mapping step to match file columns to importer fields.

Header Normalization

When auto-mapping columns to fields, Tapix normalizes headers so that spaces, dashes, and underscores are treated as interchangeable. For example, a file header named first-name will automatically map to a field defined as first_name or first name.

Custom Readers

To add support for a new file format, implement the FileReader interface and register it in the config:

config/tapix.php
'readers' => [
    'csv' => CsvReader::class,
    'txt' => CsvReader::class,
    'xlsx' => XlsxReader::class,
    'json' => \App\Imports\JsonReader::class,
],

Your custom reader must implement all four methods of the FileReader interface. The canRead() method should verify that the file exists and is in the expected format. The rows() method should return an iterable (such as a generator) to keep memory usage low when processing large files.

Copyright © 2026