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 today

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 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

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

2307d ago

Major Versions

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/250ad189b21ef862e3f0727fc0e416deb51588f7681ec35792327b1bd500e9ca?d=identicon)[langleyfoxall](/maintainers/langleyfoxall)

![](https://www.gravatar.com/avatar/aefc2575deccad83e2c9b56a15f7c9e15f27d4cfa25e908a8fa028baccacd04e?d=identicon)[catchyp](/maintainers/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

[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

19226.1k](/packages/jerome-filterable)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[aedart/athenaeum

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

255.2k](/packages/aedart-athenaeum)[ntanduy/cloudflare-d1-database

Easy configuration and setup for D1 Database connections in Laravel.

215.4k](/packages/ntanduy-cloudflare-d1-database)

PHPackages © 2026

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