Mager updated
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\ImportTemplate;
|
||||
use App\Models\ImportTemplateMapping;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ImportTemplateSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$template = ImportTemplate::query()->firstOrCreate([
|
||||
'name' => 'Person basic CSV',
|
||||
], [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'description' => 'Basic person import: name, email, phone, address',
|
||||
'source_type' => 'csv',
|
||||
'default_record_type' => 'person',
|
||||
'sample_headers' => ['first_name','last_name','email','phone','address','city','postal_code','country'],
|
||||
'is_active' => true,
|
||||
'meta' => [
|
||||
'delimiter' => ',',
|
||||
'enclosure' => '"',
|
||||
'escape' => '\\',
|
||||
],
|
||||
]);
|
||||
|
||||
$mappings = [
|
||||
['source_column' => 'first_name', 'target_field' => 'person.first_name', 'position' => 1],
|
||||
['source_column' => 'last_name', 'target_field' => 'person.last_name', 'position' => 2],
|
||||
['source_column' => 'email', 'target_field' => 'person.email', 'position' => 3],
|
||||
['source_column' => 'phone', 'target_field' => 'person.phone', 'position' => 4],
|
||||
['source_column' => 'address', 'target_field' => 'person.address.street', 'position' => 5],
|
||||
['source_column' => 'city', 'target_field' => 'person.address.city', 'position' => 6],
|
||||
['source_column' => 'postal_code', 'target_field' => 'person.address.postal_code', 'position' => 7],
|
||||
['source_column' => 'country', 'target_field' => 'person.address.country', 'position' => 8],
|
||||
];
|
||||
|
||||
foreach ($mappings as $map) {
|
||||
ImportTemplateMapping::firstOrCreate([
|
||||
'import_template_id' => $template->id,
|
||||
'source_column' => $map['source_column'],
|
||||
], [
|
||||
'target_field' => $map['target_field'],
|
||||
'position' => $map['position'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user