dmt-software/laravel-import-reader
最新稳定版本:v0.2.1
Composer 安装命令:
composer require dmt-software/laravel-import-reader
包简介
import reader that can handles huge imports
README 文档
README
Laravel bridge for dmt-software/import-reader to iterate over the contents of
(huge) imports.
Support
This package is tested on and requires laravel >= 8.0.
Installation
composer require dmt-software/laravel-import-reader
The service provider can be automatically registered by auto-discovery. Otherwise, register it manually add it to config/app.php:
'providers' => [ // ... DMT\Laravel\Import\Reader\Providers\ImportReaderServiceProvider::class, ];
To publish the configuration file:
php artisan vendor:publish --provider="DMT\Laravel\Import\Reader\Providers\ImportReaderServiceProvider"
Configuration
The configuration has entries for custom sanitizers, handlers and a custom
error handler. See the config/reader.php file for their usage or the
dmt-software/import-reader documentation.
Usage
A file called items.json contains the following data:
[ { "id": 1, "name": "item-name", // ... }, { "id": 2, "name": "item2-name", // ... }, // ... ]
That can be read into chunks that can be imported into a database:
use DMT\Laravel\Import\Reader\Facades\ImportReader; /** @var iterable<int, array> $items */ $items = ImportReader::buildToArrayReader( 'directory-to/items.json', [ 'path' => '.' ])->read(); foreach ($items as $row => $item) { // process the items if (!empty($item['name'])) { Item::updateOrCreate($item); } }
Or the reader builder can be injected into your classes or methods.
use DMT\Import\Reader\ReaderBuilder; use Illuminate\Console\Command; class MyImportCommand extends Command { protected $signature = 'import:items {file}'; public function handle(ReaderBuilder $builder) { $reader = $builder->build($this->argument('file'), []); foreach ($reader->read($this->argument('skip')) as $item) { // process item } } }
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-15