PHPackages                             ellgreen/laravel-loadfile - 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. ellgreen/laravel-loadfile

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

ellgreen/laravel-loadfile
=========================

A package to help with loading files into MySQL tables

4.1.0(2mo ago)82196.8k↓21.6%9[2 issues](https://github.com/ellgreen/laravel-loadfile/issues)[1 PRs](https://github.com/ellgreen/laravel-loadfile/pulls)MITPHPPHP ^8.2CI passing

Since May 3Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/ellgreen/laravel-loadfile)[ Packagist](https://packagist.org/packages/ellgreen/laravel-loadfile)[ RSS](/packages/ellgreen-laravel-loadfile/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (10)Versions (16)Used By (0)

Laravel Load File 💽
===================

[](#laravel-load-file-)

[![Latest Stable Version](https://camo.githubusercontent.com/d9d44c7e689d0a216b98880b57022379fd6931bf5a02dc891b40c0b882e6d7c6/68747470733a2f2f706f7365722e707567782e6f72672f656c6c677265656e2f6c61726176656c2d6c6f616466696c652f76)](//packagist.org/packages/ellgreen/laravel-loadfile)[![License](https://camo.githubusercontent.com/5f05bd973fbe22c4090d6d465648fd40f1a9d4b670fda2d9b10bc9de8b3398a2/68747470733a2f2f706f7365722e707567782e6f72672f656c6c677265656e2f6c61726176656c2d6c6f616466696c652f6c6963656e7365)](//packagist.org/packages/ellgreen/laravel-loadfile)

A package to help with loading files into MySQL tables.

This uses MySQL's LOAD DATA statement to load text files quickly into your database.

This is usually **20 times** faster than using INSERT statements according to:

### Options

[](#options)

This library currently can handle any of the options in a normal LOAD DATA statement except for the partitioned table support. This will be included in a future release of laravel-loadfile.

**Further information on the following options that can be passed to the load file builder can be found here:**

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

[](#installation)

**Requires &gt;= PHP 8.2 and &gt;= Laravel 12**

*Older versions of Laravel and PHP are supported through previous major versions of this library*

```
composer require ellgreen/laravel-loadfile
```

### Loading files

[](#loading-files)

To use local files you will need to have `local_infile` enabled for the client and server. To do this on the Laravel side you will need to add the following to the `options` part of your database config:

```
'config' => [
    PDO::MYSQL_ATTR_LOCAL_INFILE => true,
],
```

#### Simple file import

[](#simple-file-import)

```
use EllGreen\LaravelLoadFile\Laravel\Facades\LoadFile;

LoadFile::file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns(['forename', 'surname', 'employee_id'])
    ->load();
```

#### Ignoring header row

[](#ignoring-header-row)

```
LoadFile::file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns(['forename', 'surname', 'employee_id'])
    ->ignoreLines(1)
    ->load();
```

#### Specifying field options

[](#specifying-field-options)

```
LoadFile::file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns(['forename', 'surname', 'employee_id'])
    // like this
    ->fieldsTerminatedBy(',')
    ->fieldsEscapedBy('\\\\')
    ->fieldsEnclosedBy('"')
    // or
    ->fields(',', '\\\\', '"')
    ->load();
```

#### Specifying line options

[](#specifying-line-options)

```
LoadFile::file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns(['forename', 'surname', 'employee_id'])
    // like this
    ->linesStartingBy('')
    ->linesTerminatedBy('\\n')
    // or
    ->lines('', '\\n')
    ->load();
```

#### Input preprocessing (set)

[](#input-preprocessing-set)

```
LoadFile::file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns([
        DB::raw('@forename'),
        DB::raw('@surname'),
        'employee_id',
    ])
    ->set([
        'name' => DB::raw("concat(@forename, ' ', @surname)"),
    ])
    ->load();
```

#### Using a different connection

[](#using-a-different-connection)

```
LoadFile::connection('mysql')
    ->file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns(['forename', 'surname', 'employee_id'])
    ->load();
```

#### Duplicate-key and error handling

[](#duplicate-key-and-error-handling)

```
LoadFile::connection('mysql')
    ->file('/path/to/employees.csv', $local = true)
    ->replace()
    // or
    ->ignore()
    ->into('employees')
    ->load();
```

Loading data into Eloquent Models
---------------------------------

[](#loading-data-into-eloquent-models)

Simply add the `LoadsFiles` trait to your model like so:

```
use EllGreen\LaravelLoadFile\Laravel\Traits\LoadsFiles;

class User extends Model
{
    use LoadsFiles;
}
```

Then you can use the following method to load a file into that table:

```
User::loadFile('/path/to/users.csv', $local = true);
```

### Need to specify options to load the file with?

[](#need-to-specify-options-to-load-the-file-with)

Add the following method to your Model

```
class User extends Model
{
    use LoadsFiles;

    public function loadFileOptions(Builder $builder): void
    {
        $builder
            ->fieldsTerminatedBy(',')
            ->ignoreLines(1);
    }
}
```

### Or you can get an instance of the query builder on the fly

[](#or-you-can-get-an-instance-of-the-query-builder-on-the-fly)

```
User::loadFileBuilder($file, $local)
    ->replace()
    ->ignoreLines(1)
    ->load();
```

Development
-----------

[](#development)

### Check

[](#check)

Runs linting, static analysis, and unit tests.

```
composer check
```

### All tests

[](#all-tests)

Runs unit and feature tests against all support Laravel versions.

**You will need to have [docker](https://www.docker.com/) installed for these.**

```
composer test
```

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance84

Actively maintained with recent releases

Popularity48

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 93.7% 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 ~150 days

Recently: every ~380 days

Total

13

Last Release

79d ago

Major Versions

0.4.0 → 1.0.02021-05-05

1.2.0 → 2.0.02022-02-16

2.0.0 → 3.0.02023-02-28

3.1.0 → 4.0.02025-02-28

PHP version history (5 changes)0.1.0PHP ^7.4

1.2.0PHP ^7.4|^8.0

2.0.0PHP ^8.0

3.0.0PHP ^8.1

4.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17834927?v=4)[Ellis Green](/maintainers/ellgreen)[@ellgreen](https://github.com/ellgreen)

---

Top Contributors

[![ellgreen](https://avatars.githubusercontent.com/u/17834927?v=4)](https://github.com/ellgreen "ellgreen (59 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")

---

Tags

csvdatabaseinfilelaravelloadload-data-infileloaddatamysqlphptsv

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ellgreen-laravel-loadfile/health.svg)

```
[![Health](https://phpackages.com/badges/ellgreen-laravel-loadfile/health.svg)](https://phpackages.com/packages/ellgreen-laravel-loadfile)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[awobaz/compoships

Laravel relationships with support for composite/multiple keys

1.2k11.7M47](/packages/awobaz-compoships)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.3M19](/packages/bavix-laravel-wallet)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)

PHPackages © 2026

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