PHPackages                             dlucca/backpack-import - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. dlucca/backpack-import

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

dlucca/backpack-import
======================

Import operation for Backpack Admin Panel

72801PHP

Since Mar 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/dluccajose/backpack-import)[ Packagist](https://packagist.org/packages/dlucca/backpack-import)[ RSS](/packages/dlucca-backpack-import/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

dlucca/backpack-import
======================

[](#dluccabackpack-import)

`dlucca/backpack-import` is a Laravel package and a Backpack Laravel addon. Allows you to add a "import operation" to your CRUDs to easily import records from an excel file into to your database. This is a personal project and still under development, its not recommended to use it in a production environment. If you want to play with it, you can install this package as a local composer package, as still is not available via composer install.

Features
========

[](#features)

- Import records into your DB from an excel file
- Validations
- Customize import logic
- UI for file upload

Future features
===============

[](#future-features)

- Table with a preview of the data to be imported

Preview
=======

[](#preview)

Coming soon...

Example
=======

[](#example)

```
...
class CityCrudController extends CrudController
{
    ...
    use \Dlucca\BackpackImport\ImportOperation;

    protected function setupImportOperation()
    {
        $this->backpackImport->setUpdateField('code');

        $this->backpackImport->setImportValidationRules([
            'name' => ['required'],
        ]);

        $this->backpackImport->setImportColumnMapping([
            'name' => 'Ciudad',
            'code' => 'Codigo',
            'created_at' => [
                'name' => 'Fecha',
                'import_logic' => function(&$entry, $row, $value) {
                    if ($value) {
                        $entry->created_at = Date::excelToDateTimeObject($value);
                    }
                },
            ],
        ]);
    }
    ...

```

Documentation
=============

[](#documentation)

- Setup
- Insert records
- Update records
- Validations
- Relationships
- Views
- Hooks
- Advance options

Setup
-----

[](#setup)

Install with composer

```
    composer require dlucca/backpack-import:dev-master
```

To start, you have to use the operation in your backpack crud by adding the trait `use \Dlucca\BackpackImport\ImportOperation;`.Then you should create a function `protected function setupImportOperation()`. Inside this function you will have access to the Importer object via `$this->backpackImport`.

Insert records
--------------

[](#insert-records)

To import records into to your database yo have to tell importer which columns from the excel correspond to your table fields, you can do it using the method `$this->backpackImport->setImportColumnMapping()`, this method accepts and associative array where the keys is the name of your field in the table and the value is the name in your excel column header. For example, lets assume we have a excel file in which the header columns are "Name" and "Age", and the fields in our people table are "first\_name" and "person\_age"

```
$this->backpackImport->setImportColumnMapping([
  'first_name' => 'Name',
  'person_age' => 'Age',
]);

```

#### Advanced options

[](#advanced-options)

For more complex operations, you can provide additional options to the array:

```
$this->backpackImport->setImportColumnMapping([
    'complex_field' => [
        'name' => 'Nombre'                  // Name of the column in the excel file
        'set_after_save' => true            // If true, the import logic will be execute after the model
                                            // was saved
        'import logic' => function (&$entry, $row, $value, $operation) {     // Provide a custom logic for the import

        },
        'fake' => true                      // If true, makes the column data available in the row
                                            // variable, but it wont execute any import logic or be assign
                                            // to any property on the model. It is usefully when you need to
                                            // use that data in other field
    ]
]);

```

Update Records
--------------

[](#update-records)

For default, every time you do a import, the package will try to insert the records in the database, even if already exists. If you want to update the records that already exist, you can set an "update field". The package will do a search by the field provided, and will update the record if there any result.

```
$this->backpackImport->setUpdateField('code');

```

Validations
-----------

[](#validations)

When performing the upload and import of the excel file, you can set validations just that you would do in your typical create/update CRUD.

Set validations rule

```
$this->backpackImport->setImportValidationRules([
    'name' => ['required'],
]);

```

Set validation attributes names

```
$this->backpackImport->setImportValidationAttributes([
    'name' => 'Nombre',
]);

```

Hooks
-----

[](#hooks)

Hooks are functions that you can attach to execute in different moments of the import operation. List of available hooks

```
$this->backpackImport->doHook('before_import', function ($mappedRows) {});
$this->backpackImport->doHook('before_insert', function ($entry, $row) {});
$this->backpackImport->doHook('after_insert', function ($entry, $row) {});
$this->backpackImport->doHook('after_import', function () {});

```

Set template example for download
---------------------------------

[](#set-template-example-for-download)

Into `setupImportOperation()` add:

```
    protected function setupImportOperation()
    {
        ...

        $this->crud->set('import.example_file_url', Storage::url('file.xlsx'));

        ...

    }
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2e58e8ca3a276cbaaf5d807c400657c58f6e0b660b67ab622d8c0e9d19703aea?d=identicon)[fkmurphy](/maintainers/fkmurphy)

---

Top Contributors

[![dluccajosetw](https://avatars.githubusercontent.com/u/70543645?v=4)](https://github.com/dluccajosetw "dluccajosetw (21 commits)")[![dluccajose](https://avatars.githubusercontent.com/u/6971378?v=4)](https://github.com/dluccajose "dluccajose (12 commits)")[![fkmurphy](https://avatars.githubusercontent.com/u/9388504?v=4)](https://github.com/fkmurphy "fkmurphy (2 commits)")

---

Tags

backpackbackpack-for-laravelcrudexcellaravel

### Embed Badge

![Health badge](/badges/dlucca-backpack-import/health.svg)

```
[![Health](https://phpackages.com/badges/dlucca-backpack-import/health.svg)](https://phpackages.com/packages/dlucca-backpack-import)
```

###  Alternatives

[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.2k57.6M131](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)[setasign/tfpdf

This class is a modified version of FPDF that adds UTF-8 support. The latest version is based on FPDF 1.85.

426.1M30](/packages/setasign-tfpdf)[aspera/xlsx-reader

Spreadsheet reader library for XLSX files

52742.2k5](/packages/aspera-xlsx-reader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
