PHPackages                             langleyfoxall/eloquent-csv-importer - 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. [Database &amp; ORM](/categories/database)
4. /
5. langleyfoxall/eloquent-csv-importer

ActiveLibrary[Database &amp; ORM](/categories/database)

langleyfoxall/eloquent-csv-importer
===================================

Easily map CSV files to Eloquent models

v1.1.0(6y ago)73572MITPHPPHP ^7.0.0CI failing

Since Nov 9Pushed 6y ago1 watchersCompare

[ Source](https://github.com/langleyfoxall/eloquent-csv-importer)[ Packagist](https://packagist.org/packages/langleyfoxall/eloquent-csv-importer)[ RSS](/packages/langleyfoxall-eloquent-csv-importer/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (8)Dependencies (7)Versions (11)Used By (0)

💾 Eloquent CSV Importer
=======================

[](#-eloquent-csv-importer)

[![Travis Status](https://camo.githubusercontent.com/3c40583caf642d0ea138c4b6916861bff9b6a05a4de722d8131c347aa51f1186/68747470733a2f2f7472617669732d63692e6f72672f6c616e676c6579666f78616c6c2f656c6f7175656e742d6373762d696d706f727465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/langleyfoxall/eloquent-csv-importer)

Eloquent CSV Importer helps create and store column maps to enable the easy conversion of CSV data to Eloquent models

 [![](assets/images/example-code.png)](assets/images/example-code.png)

Installation
------------

[](#installation)

Eloquent CSV Importer can be easily installed using Composer. Just run the following command from the root of your project.

```
composer require langleyfoxall/eloquent-csv-importer

```

The service provider is to set to be auto discovered in Laravel 5.5+ - in older versions you will have to manually register it in `config/app.php`

```
LangleyFoxall\EloquentCSVImporter\EloquentCSVImporterServiceProvider::class

```

After this, publish the vendor files to copy the CSV definitions migrations to your migrations folder.

```
php artisan vendor:publish

```

Documentation
-------------

[](#documentation)

#### Getting started

[](#getting-started)

1. Publish the migrations, add any additional columns to the csv\_defintions table you may want &amp; migrate.

```
php artisan migrate

```

2. Add the `CSVMappable` &amp; `HasCSVDefinitions` traits to the model you want to store CSV definitions agaisnt.

```
...

use LangleyFoxall\EloquentCSVImporter\Traits\CSVMappable;

class Product extends Model
{
    use CSVMappable, HasCSVDefinitions;

    ...

}
```

3. Specify the columns that you want to be allowed to be mapped by overriding the `getCSVMappableColumns()` function, by default it uses all the columns of the model.

```
public static function getCSVMappableColumns()
{
    return collect([
        'product_name',
    ]);
}
```

3. Create a CSV definition for your model you want to map to

```
$definition = (new CSVDefinitionFactory(Product::class))
    ->mapColumns(['product ID' => 'product_name'])
    ->setMeta([
        'name' => '2009 - 2010 products',
        'description' => 'Definitions for the 2009 - 2010 product lists',
    ])->create();
```

4. You can now use the created definition to convert CSV files / strings into the related models.

```
$def = Product::first()->CSVDefinitions()->first;
$products = $def->makeModels($csvFile, []);
```

#### Updating by columns

[](#updating-by-columns)

Eloquent CSV Importer allows not only the creation of models from a CSV but the updating of models based on specified keys in the CSV.

Lets say you have the follow CSV:

product IDpriceproduct-00112.99product-00213.99And the following code to map your CSV file into your models

```
$products = $def->makeModels($csvFile, ['product ID']);
```

The above code will now update or create a product model by finding a product where `product_name` is equal to the value in the current CSV row or by creating a new one with the data in the current CSV row if one doesn't already exist.

You can pass in multiple keys to update like so:

```
$products = $def->makeModels($csvFile, ['product ID', 'price']);
```

This will update an existing product where both values in the product are equal to the specified values in the CSV row.

#### Data item manipulation

[](#data-item-manipulation)

If you wish, you can manipulate the data as it is being imported from the CSV. To do this, you must create a new a data item manipulator function, and then set it against the CSV definition.

The data item manipulator function will receive the data item key, value, and a copy of the entire row from the CSV. After making changes, it should return the modified data item value.

The example below converts any value it receives to uppercase.

```
$definition->setDataItemManipulator(function($key, $value, $row) {
    return strtoupper($value);
});
```

The data item manipulator should be set before you call the `makeModels` or `createModels` methods.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~72 days

Recently: every ~107 days

Total

7

Last Release

2356d ago

Major Versions

v0.0.2-alpha → v1.0.0-alpha2018-11-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18738623?v=4)[Codebased Ltd](/maintainers/langleyfoxall)[@langleyfoxall](https://github.com/langleyfoxall)

![](https://avatars.githubusercontent.com/u/105655054?v=4)[catchyp](/maintainers/catchyp)[@catchyp](https://github.com/catchyp)

---

Top Contributors

[![AlexCatch](https://avatars.githubusercontent.com/u/13490042?v=4)](https://github.com/AlexCatch "AlexCatch (32 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/langleyfoxall-eloquent-csv-importer/health.svg)

```
[![Health](https://phpackages.com/badges/langleyfoxall-eloquent-csv-importer/health.svg)](https://phpackages.com/packages/langleyfoxall-eloquent-csv-importer)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15104.9k4](/packages/calebdw-larastan)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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