@vidhyaprakash85 Can you show your TeacherImportService.php class?
Jan 9, 2024
6
Level 2
Laravel Excel upload file from request and check email fired
I have laravel excel import test which first check whether columns are matched or not. If columns are not matched it will send an email to the user. I need to test this first.
test('superadmin can able to upload wrong file', function () {
$this->withoutExceptionHandling();
$branches = Branch::select('id', 'name')->get();
$response = $this->get(route('user.create'));
$response->assertSee("Teacher User Import");
Excel::fake();
Storage::fake();
$file = UploadedFile::fake()->create(
base_path('tests/Files/teacher-wrong-file.xlsx'),
'teacher-wrong-file.xlsx'
);
$data = [
'teacherbranch' => $branches->first()->id,
'teacherimportfile' => $file,
"submit" => 'TeacherImport',
];
$response = $this->post(route('user.store'), $data);
$response->assertStatus(302);
$response->assertRedirect(route('user.index'));
});
I have getting the error message
Undefined array key 0
at app/Services/TeacherImportService.php:35
31▕ private function validateExcelColumnNames($file): bool
32▕ {
33▕ // Use the Excel facade to check column names
34▕ $columnNames = (new HeadingRowImport)->toArray($file);
➜ 35▕ $convertedColumnNames = (array_values($columnNames[0][0]));
36▕
37▕ // Define the expected column names
38▕ $expectedColumns = ['lecturer_code', 'lecturer_name', 'lecturer_status', 'position_code', 'position_name', 'lecturer_category', 'mininmum_teaching_hours', 'maximum_teaching_hours', 'department_name', 'section_name'];
39▕
Please help in uploading file issue and the sending email.
Please or to participate in this conversation.