Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/inmanturbo/volt-csv-import-field-mapper

Component to allow user to map fields for csv imports
https://github.com/inmanturbo/volt-csv-import-field-mapper

Last synced: 12 days ago
JSON representation

Component to allow user to map fields for csv imports

Awesome Lists containing this project

README

        

# volt-csv-import-field-mapper

Component to allow user to map fields for csv imports

## Tailwind Purge
```
'./vendor/inmanturbo/volt-csv-import-field-mapper/resources/views/**/*.blade.php',
```

## Usage

```php
use Illuminate\Support\Facades\Storage;
use Spatie\SimpleExcel\SimpleExcelReader;
use Inmanturbo\ImportFieldMapper\ImportFieldMapper;
use App\Models\Contact;

use function Livewire\Volt\{on, state};

state([
'importMap' => [
'display_name' => 'Display Name',
'email' => 'Email',
],
'uploadDialog' => false,
]);

on([
'import-field-mapper-updated-uploaded-file' =>
fn($uploadedCsvPath) =>
$this->uploadedCsvPath = Storage::path(
config('import-field-mapper.path')
. DIRECTORY_SEPARATOR
. $uploadedCsvPath
),
'import-field-mapper-updated-mapped-import-fields' =>
fn($mappedImportFields) =>
$this->mappedImportFields = $mappedImportFields,
]);

$importCsv = function () {
$path = Storage::path(config('import-field-mapper.path'). '/' . $this->uploadedCsvFile);
$reader = SimpleExcelReader::create($path);

$reader->getRows()->each(function ($row) {
$row = ImportFieldMapper::row($row)->toArray();

$action = new class($row, $this->importMap, $this->mappedImportFields) {
use \Inmanturbo\ImportFieldMapper\HandlesMappedEloquentAttributes;

protected modelClass()
{
return \App\Models\Contact::class;
}
}

$action->handle();
});

$this->uploadedCsvFile = null;
$this->uploadDialog = false;
$this->banner($reader->getRows()->count() . ' Contacts imported successfully');
};


{{_('Upload Csv')}}



{{ __('Import Contacts from CSV file') }}


@livewire('import-field-mapper', ['importFieldMap' => $this->importMap,])




{{ __('Cancel') }}





{{ __('Save') }}



```