Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/inmanturbo/volt-csv-import-field-mapper
- Owner: inmanturbo
- License: mit
- Created: 2024-06-25T16:23:27.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-09T16:01:48.000Z (4 months ago)
- Last Synced: 2024-10-12T15:21:06.504Z (26 days ago)
- Language: Blade
- Size: 83 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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') }}
```