Import Action

Nothing is being imported and the job fails when I do queue:work. I am not being able to dd in any functions in the importer as well to know where it went wrong. It is just continuously failing only !!!
Solution:
I got it. I sent the required value in the options where I call the importer.
Jump to solution
15 Replies
LeandroFerreira
LeandroFerreira9mo ago
Did you check the failed_jobs table?
namrata
namrataOP9mo ago
yes but there is no error, just datas only
namrata
namrataOP9mo ago
No description
namrata
namrataOP9mo ago
also it is trying to upload all the values in the csv instead of just the ones that I have asked I don't know what I have missed
toeknee
toeknee9mo ago
Been through this a lot today 😛 it's failing because of your resolveRecord using I suspect. Check your laravel.log
namrata
namrataOP9mo ago
it is failing due to my database requirements. but I could not figure out how can I pass the data that is not in the csv while uploading.
toeknee
toeknee9mo ago
Several ways, castUsing or fillRecordWith within the individual fields. If you need to pass in more data outside of the scope you can manipluate the data in the fillRecordUsing i.e.
public function resolveRecord(): ?YourModel
{
$this->data['team_id'] = $team_id;
}
public function resolveRecord(): ?YourModel
{
$this->data['team_id'] = $team_id;
}
namrata
namrataOP9mo ago
Is there any way to pass data in the import from where it is being used ? Like I have userimporter but I have this in program model and I need to pass a specific organization id in the importer itself. Is it possible ?
toeknee
toeknee9mo ago
so will the oranization id be in the importer? Can you clarify the exact flow?
namrata
namrataOP9mo ago
I have a resource called organization resource whose edit organization has the importer. The importer fills or uploads the data in another resource called invitations which has organization id. The importer doesn’t have the organization id. So now I have to pass the selected organization id to the importer at the time of uploading it
Solution
namrata
namrata9mo ago
I got it. I sent the required value in the options where I call the importer.
Urufu
Urufu9mo ago
Hi, I'm trying to import a CSV file that contains Employee, Payment and Detail data, I've been trying to do this the following way, but I always get the error:
[previous exception] [object] (PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dni' in 'field list' at D:\\LaravelVemto\\cpagos-filament-l11\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:592)
[previous exception] [object] (PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dni' in 'field list' at D:\\LaravelVemto\\cpagos-filament-l11\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:592)
However, the 'dni' field (which is the first in ImportColum), is in the Employee model and it seems that it wants to insert it into Payment, any suggestions? I also tried with the hooks and it gives me the same result, my current code is:
public function resolveRecord(): ?Payment
{
$employee = $this->createOrUpdateEmployee();
$payment = $this->createOrUpdatePayment($employee);
return $payment;
}

protected function createOrUpdateEmployee(): Employee
{
return Employee::updateOrCreate(
['dni' => $this->data['dni']],
[
'name' => $this->data['name'],
]
);
}

protected function createOrUpdatePayment(Employee $employee): Payment
{
[$year, $month] = $this->parsePeriod($this->data['periodo']);

$payment = Payment::updateOrCreate(
[
'employee_id' => $employee->id,
'year' => $year,
'month' => $month,
],
[
'user_id' => auth()->id(),
'total_haber' => $this->data['total_haber'],

'pension_type' => $this->data['pension_type'],

]
);
return $payment;
}
public function resolveRecord(): ?Payment
{
$employee = $this->createOrUpdateEmployee();
$payment = $this->createOrUpdatePayment($employee);
return $payment;
}

protected function createOrUpdateEmployee(): Employee
{
return Employee::updateOrCreate(
['dni' => $this->data['dni']],
[
'name' => $this->data['name'],
]
);
}

protected function createOrUpdatePayment(Employee $employee): Payment
{
[$year, $month] = $this->parsePeriod($this->data['periodo']);

$payment = Payment::updateOrCreate(
[
'employee_id' => $employee->id,
'year' => $year,
'month' => $month,
],
[
'user_id' => auth()->id(),
'total_haber' => $this->data['total_haber'],

'pension_type' => $this->data['pension_type'],

]
);
return $payment;
}
I hope you can give me some ideas, thanks.
namrata
namrataOP9mo ago
Can you explain in which database are you trying to write the import values ? In employee or payment ?
Urufu
Urufu9mo ago
Traducción al inglés: Hi, thanks for replying. In the CSV, I have information for both tables, Employee and Payment. I wanted to first register the employee data with
$employee = $this->createOrUpdateEmployee();
$employee = $this->createOrUpdateEmployee();
, and then register their payments with $payment = $this->createOrUpdatePayment($employee); Each row in the CSV has this information. In summary, I need to insert into both tables for each row that is processed.
namrata
namrataOP8mo ago
If you need to insert in the both tables all the rows in the csv then dni must also be in payment. Since it looks like you are trying to upload all the data in the both fields
Want results from more Discord servers?
Add your server