{"id":30880612,"url":"https://github.com/ellgreen/laravel-loadfile","last_synced_at":"2025-09-08T07:05:25.087Z","repository":{"id":43835675,"uuid":"363983841","full_name":"ellgreen/laravel-loadfile","owner":"ellgreen","description":"MySQL Load Data Infile Support For Laravel","archived":false,"fork":false,"pushed_at":"2025-02-28T11:10:38.000Z","size":333,"stargazers_count":82,"open_issues_count":3,"forks_count":10,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-04T14:55:31.572Z","etag":null,"topics":["csv","database","infile","laravel","load","load-data-infile","loaddata","mysql","php","tsv"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ellgreen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-03T15:57:29.000Z","updated_at":"2025-04-10T04:00:54.000Z","dependencies_parsed_at":"2024-11-25T11:39:43.359Z","dependency_job_id":"45f45dac-c03b-4f32-a3ca-353d3f5ef9a0","html_url":"https://github.com/ellgreen/laravel-loadfile","commit_stats":{"total_commits":44,"total_committers":1,"mean_commits":44.0,"dds":0.0,"last_synced_commit":"e9d8c0e13ef06d1179e90c838380811adf497f3d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/ellgreen/laravel-loadfile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ellgreen%2Flaravel-loadfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ellgreen%2Flaravel-loadfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ellgreen%2Flaravel-loadfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ellgreen%2Flaravel-loadfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ellgreen","download_url":"https://codeload.github.com/ellgreen/laravel-loadfile/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ellgreen%2Flaravel-loadfile/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274146863,"owners_count":25230168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","database","infile","laravel","load","load-data-infile","loaddata","mysql","php","tsv"],"created_at":"2025-09-08T07:05:23.376Z","updated_at":"2025-09-08T07:05:25.058Z","avatar_url":"https://github.com/ellgreen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Load File 💽\n\n[![Latest Stable Version](https://poser.pugx.org/ellgreen/laravel-loadfile/v)](//packagist.org/packages/ellgreen/laravel-loadfile)\n[![License](https://poser.pugx.org/ellgreen/laravel-loadfile/license)](//packagist.org/packages/ellgreen/laravel-loadfile)\n\nA package to help with loading files into MySQL tables.\n\nThis uses MySQL's LOAD DATA statement to load text files quickly into your database.\n\nThis is usually **20 times** faster than using INSERT statements according to:\nhttps://dev.mysql.com/doc/refman/8.0/en/insert-optimization.html\n\n### Options\n\nThis library currently can handle any of the options in a normal\nLOAD DATA statement except for the partitioned table support. This will\nbe included in a future release of laravel-loadfile.\n\n**Further information on the following options that can be passed to the\nload file builder can be found here:**\n\nhttps://dev.mysql.com/doc/refman/8.0/en/load-data.html\n\n## Installation\n\n**Requires \u003e= PHP 8.2 and \u003e= Laravel 12**\n\n*Older versions of Laravel and PHP are supported through previous major versions of this library*\n\n```bash\ncomposer require ellgreen/laravel-loadfile\n```\n\n### Loading files\n\nTo use local files you will need to have `local_infile` enabled for\nthe client and server. To do this on the Laravel side you will need\nto add the following to the `options` part of your database config:\n```php\n'config' =\u003e [\n    PDO::MYSQL_ATTR_LOCAL_INFILE =\u003e true,\n],\n```\n\n#### Simple file import\n\n```php\nuse EllGreen\\LaravelLoadFile\\Laravel\\Facades\\LoadFile;\n\nLoadFile::file('/path/to/employees.csv', $local = true)\n    -\u003einto('employees')\n    -\u003ecolumns(['forename', 'surname', 'employee_id'])\n    -\u003eload();\n```\n\n#### Ignoring header row\n\n```php\nLoadFile::file('/path/to/employees.csv', $local = true)\n    -\u003einto('employees')\n    -\u003ecolumns(['forename', 'surname', 'employee_id'])\n    -\u003eignoreLines(1)\n    -\u003eload();\n```\n\n#### Specifying field options\n\n```php\nLoadFile::file('/path/to/employees.csv', $local = true)\n    -\u003einto('employees')\n    -\u003ecolumns(['forename', 'surname', 'employee_id'])\n    // like this\n    -\u003efieldsTerminatedBy(',')\n    -\u003efieldsEscapedBy('\\\\\\\\')\n    -\u003efieldsEnclosedBy('\"')\n    // or\n    -\u003efields(',', '\\\\\\\\', '\"')\n    -\u003eload();\n```\n\n#### Specifying line options\n\n```php\nLoadFile::file('/path/to/employees.csv', $local = true)\n    -\u003einto('employees')\n    -\u003ecolumns(['forename', 'surname', 'employee_id'])\n    // like this\n    -\u003elinesStartingBy('')\n    -\u003elinesTerminatedBy('\\\\n')\n    // or\n    -\u003elines('', '\\\\n')\n    -\u003eload();\n```\n\n#### Input preprocessing (set)\n\n```php\nLoadFile::file('/path/to/employees.csv', $local = true)\n    -\u003einto('employees')\n    -\u003ecolumns([\n        DB::raw('@forename'),\n        DB::raw('@surname'),\n        'employee_id',\n    ])\n    -\u003eset([\n        'name' =\u003e DB::raw(\"concat(@forename, ' ', @surname)\"),\n    ])\n    -\u003eload();\n```\n\n#### Using a different connection\n\n```php\nLoadFile::connection('mysql')\n    -\u003efile('/path/to/employees.csv', $local = true)\n    -\u003einto('employees')\n    -\u003ecolumns(['forename', 'surname', 'employee_id'])\n    -\u003eload();\n```\n\n#### Duplicate-key and error handling\n\n```php\nLoadFile::connection('mysql')\n    -\u003efile('/path/to/employees.csv', $local = true)\n    -\u003ereplace()\n    // or\n    -\u003eignore()\n    -\u003einto('employees')\n    -\u003eload();\n```\n\n\n## Loading data into Eloquent Models\n\nSimply add the `LoadsFiles` trait to your model like so:\n\n```php\nuse EllGreen\\LaravelLoadFile\\Laravel\\Traits\\LoadsFiles;\n\nclass User extends Model\n{\n    use LoadsFiles;\n}\n```\n\nThen you can use the following method to load a file into that table:\n\n```php\nUser::loadFile('/path/to/users.csv', $local = true);\n```\n\n### Need to specify options to load the file with?\n\nAdd the following method to your Model\n\n```php\nclass User extends Model\n{\n    use LoadsFiles;\n\n    public function loadFileOptions(Builder $builder): void\n    {\n        $builder\n            -\u003efieldsTerminatedBy(',')\n            -\u003eignoreLines(1);\n    }\n}\n```\n\n### Or you can get an instance of the query builder on the fly\n\n```php\nUser::loadFileBuilder($file, $local)\n    -\u003ereplace()\n    -\u003eignoreLines(1)\n    -\u003eload();\n```\n\n## Development\n\n### Check\n\nRuns linting, static analysis, and unit tests.\n\n```shell\ncomposer check\n```\n\n### All tests\n\nRuns unit and feature tests against all support Laravel versions.\n\n**You will need to have [docker](https://www.docker.com/) installed for these.**\n\n```shell\ncomposer test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fellgreen%2Flaravel-loadfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fellgreen%2Flaravel-loadfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fellgreen%2Flaravel-loadfile/lists"}