MahmoudMansour
Importer Not Working
Hi , inside MedicalSourceResource class , no data imported i got notification with processing , aslo i have been checked the import table for issues and it not errors
Has One discount relation ,
public static function table(Table $table): Table
{
return $table
->headerActions([
ImportAction::make()
->importer(MedicalSourceImporter::class)
])
public static function table(Table $table): Table
{
return $table
->headerActions([
ImportAction::make()
->importer(MedicalSourceImporter::class)
])
#IMPORTER
class MedicalSourceImporter extends Importer
{
protected static ?string $model = MedicalSource::class;
public static function getColumns(): array
{
return [
ImportColumn::make('specialist_id')
->numeric()
->rules(['integer']),
ImportColumn::make('type')
->relationship(),
ImportColumn::make('name')
->rules(['max:255']),
// etc ... etc ...
ImportColumn::make('discounts.xrays')
->label(__('xrays_discount'))
->rules(['max:100']),
ImportColumn::make('discounts.pathology')
->label(__('pathology'))
->rules(['max:100']),
ImportColumn::make('discounts.local')
->label(__('local'))
->rules(['max:100']),
#IMPORTER
class MedicalSourceImporter extends Importer
{
protected static ?string $model = MedicalSource::class;
public static function getColumns(): array
{
return [
ImportColumn::make('specialist_id')
->numeric()
->rules(['integer']),
ImportColumn::make('type')
->relationship(),
ImportColumn::make('name')
->rules(['max:255']),
// etc ... etc ...
ImportColumn::make('discounts.xrays')
->label(__('xrays_discount'))
->rules(['max:100']),
ImportColumn::make('discounts.pathology')
->label(__('pathology'))
->rules(['max:100']),
ImportColumn::make('discounts.local')
->label(__('local'))
->rules(['max:100']),
public function handleRecordCreation(MedicalSource $medicalSource, array $record): void
{
$discountData = [
'statement' => $record['statement'],
'surgical' => $record['surgical'],
'emergency' => $record['emergency'],
'labs' => $record['labs'],
'xrays' => $record['xrays'],
'internal' => $record['internal'],
'other' => $record['other'],
'pathology' => $record['pathology'],
'local' => $record['local'],
'imported' => $record['imported'],
'cosmetic' => $record['cosmetic'],
];
$medicalSource->discounts->create($discountData);
}
public function handleRecordCreation(MedicalSource $medicalSource, array $record): void
{
$discountData = [
'statement' => $record['statement'],
'surgical' => $record['surgical'],
'emergency' => $record['emergency'],
'labs' => $record['labs'],
'xrays' => $record['xrays'],
'internal' => $record['internal'],
'other' => $record['other'],
'pathology' => $record['pathology'],
'local' => $record['local'],
'imported' => $record['imported'],
'cosmetic' => $record['cosmetic'],
];
$medicalSource->discounts->create($discountData);
}
2 replies