PHP code example of dmt-software / laravel-import-reader

1. Go to this page and download the library: Download dmt-software/laravel-import-reader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dmt-software / laravel-import-reader example snippets


'providers' => [
    // ...
    DMT\Laravel\Import\Reader\Providers\ImportReaderServiceProvider::class,
];

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);
    }
}

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
        }
    }
}