{"id":18253528,"url":"https://github.com/bayareawebpro/laravel-simple-csv","last_synced_at":"2025-07-29T14:11:12.234Z","repository":{"id":32793149,"uuid":"142766243","full_name":"bayareawebpro/laravel-simple-csv","owner":"bayareawebpro","description":"A simple CSV importer / exporter for Laravel Framework that supports Lazy Collections and Stream Downloads","archived":false,"fork":false,"pushed_at":"2025-04-29T11:27:58.000Z","size":607,"stargazers_count":17,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-03T16:12:26.607Z","etag":null,"topics":["csv","download","export","import","laravel","lazycollection","simple","splitting-utility"],"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/bayareawebpro.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":"2018-07-29T14:07:39.000Z","updated_at":"2025-04-29T11:26:09.000Z","dependencies_parsed_at":"2025-04-04T16:33:49.650Z","dependency_job_id":"63a33174-ccf2-48a1-90dd-775235aff1dd","html_url":"https://github.com/bayareawebpro/laravel-simple-csv","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/bayareawebpro/laravel-simple-csv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayareawebpro%2Flaravel-simple-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayareawebpro%2Flaravel-simple-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayareawebpro%2Flaravel-simple-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayareawebpro%2Flaravel-simple-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bayareawebpro","download_url":"https://codeload.github.com/bayareawebpro/laravel-simple-csv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayareawebpro%2Flaravel-simple-csv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267701293,"owners_count":24130447,"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-07-29T02:00:12.549Z","response_time":2574,"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","download","export","import","laravel","lazycollection","simple","splitting-utility"],"created_at":"2024-11-05T10:07:05.196Z","updated_at":"2025-07-29T14:11:12.202Z","avatar_url":"https://github.com/bayareawebpro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Simple CSV\n\n![](https://github.com/bayareawebpro/laravel-simple-csv/workflows/ci/badge.svg)\n![](https://codecov.io/gh/bayareawebpro/laravel-simple-csv/branch/master/graph/badge.svg)\n![](https://img.shields.io/github/v/release/bayareawebpro/laravel-simple-csv.svg)\n![](https://img.shields.io/packagist/dt/bayareawebpro/laravel-simple-csv.svg)\n![](https://img.shields.io/badge/License-MIT-success.svg)\n\n\u003e https://packagist.org/packages/bayareawebpro/laravel-simple-csv\n\n## Features\n- Import to LazyCollection.\n- Export from Collection, LazyCollection, Iterable, Generator, Array.\n- Low(er) Memory Consumption by use of LazyCollection Generators.\n- Uses Native PHP SplFileObject.\n- Facade Included.\n\n## Installation\nRequire the package and Laravel will Auto-Discover the Service Provider.\n\n```\ncomposer require bayareawebpro/laravel-simple-csv\n```\n\n## Usage:\n\nInvokable classes can be passed to the import method allowing you to customize\nhow each row is processed. Two classes to handle numerics \nand null values have been supplied.\n\n```php\nuse BayAreaWebPro\\SimpleCsv\\SimpleCsv;\nuse BayAreaWebPro\\SimpleCsv\\Casts\\EmptyValuesToNull;\nuse BayAreaWebPro\\SimpleCsv\\Casts\\NumericValues;\n\n$lazyCsvCollection = SimpleCsv::import(storage_path('collection.csv'), [\n    EmptyValuesToNull::class,\n    NumericValues::class,\n]);\n```\n\n### Invokable Classes\n\n**Dependency Injection:** Invokable classes can typehint required dependencies in a \nconstructor method when defined.\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace App\\Csv\\Casts;\n\nuse Carbon\\Carbon;\n\nclass Timestamps\n{\n    /** Invoked for each row in import collection. */\n    public function __invoke(array $item): array\n    {\n        foreach ($item as $key =\u003e $value){\n            if(in_array($key, ['created_at', 'updated_at'])){\n                $item[$key] = Carbon::parse($value);\n            }\n        }\n        return $item;\n    }\n}\n```\n\n### Export to File\n```php\nuse BayAreaWebPro\\SimpleCsv\\SimpleCsv;\n\n// Collection\nSimpleCsv::export(\n    Collection::make(...),\n    storage_path('collection.csv')\n);\n\n// LazyCollection\nSimpleCsv::export(\n    LazyCollection::make(...),\n    storage_path('collection.csv')\n);\n\n// Generator (Cursor)\nSimpleCsv::export(\n    User::query()-\u003ewhere(...)-\u003elimit(500)-\u003ecursor(),\n    storage_path('collection.csv')\n);\n\n// Array\nSimpleCsv::export(\n    [...],\n    storage_path('collection.csv')\n);\n```\n\n### Export Download Stream\n\n```php\nuse BayAreaWebPro\\SimpleCsv\\SimpleCsv;\n\nreturn SimpleCsv::download([...], 'download.csv');\n```\n\n#### Override Options\n```php\nuse Illuminate\\Support\\Facades\\Config;\n\nConfig::set('simple-csv.delimiter', ...);\nConfig::set('simple-csv.enclosure', ...);\nConfig::set('simple-csv.escape', ...);\n```\n\n## Or, Create a Config File\n\n`config/simple-csv.php`\n\n```php\nreturn [\n    'delimiter' =\u003e '?',\n    'enclosure' =\u003e '?',\n    'escape'    =\u003e '?',\n];\n```\n\n## File Splitting Utility\nA file splitting utility has been included that will break large CSV files into chunks \n(while retaining column headers) which you can move/delete after importing. \nThis can help with automating the import of large data sets.\n\nTip: Find your Bash Shell Binary Path: `which sh`\n\n```\n/bin/sh vendor/bayareawebpro/laravel-simple-csv/split-csv.sh /Projects/laravel/storage/big-file.csv 5000\n\nFile Output:\n/Projects/laravel/storage/big-file-chunk-1.csv (chunk of 5000)\n/Projects/laravel/storage/big-file-chunk-2.csv (chunk of 5000)\n/Projects/laravel/storage/big-file-chunk-3.csv (chunk of 5000)\netc...\n```\n\n## Speed Tips\n- Using Lazy Collections is the preferred method.\n- Using the queue worker, you can import a several thousand rows at a time without much impact.\n- Be sure to use \"Database Transactions\" and \"Timeout Detection\" to insure safe imports.\n- [Article: How to Insert \u0026 Update Many at Once](https://medium.com/@danielalvidrez/laravel-query-builder-macros-fe176d34135e)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayareawebpro%2Flaravel-simple-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbayareawebpro%2Flaravel-simple-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayareawebpro%2Flaravel-simple-csv/lists"}