Level 25
Oct 30, 2020
2
Level 1
File "" does not exist error in Laravel Excel
When I try to upload excel file in the server it shows this error. My php version is 7.2.33 and using maatwebsite/excel version "3.1.23"
Here is my controller code:
$this->validate($request, [
'employee_list' => 'required|mimes:xlsx,xls',
'corporate_id' => 'required',
]);
$file = $request->file('employee_list');
$import = new EmployeeImport($request->corporate_id);
$import->import($file);
if ($import->failures()->isNotEmpty()) {
return back()->withFailures($import->failures());
}
Here is EmployeeImport file code
class EmployeeImport implements ToModel,WithHeadingRow,SkipsOnError,WithValidation,SkipsOnFailure,WithBatchInserts,WithChunkReading
{
use Importable,SkipsErrors,SkipsFailures;
private $corporate_id;
public function __construct($corporate_id)
{
$this->corporate_id = $corporate_id;
}
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new CorporateEmployee([
'phone_no' => $row['phone_number'],
'company_id' => $this->corporate_id
]);
}
public function rules(): array
{
return [
'*.phone_number' => ['regex:/(01)[0-9]{9}/','unique:corporate_employees,phone_no']
];
}
public function batchSize(): int
{
return 100;
}
public function chunkSize(): int
{
return 100;
}
}
I have also used
enctype="multipart/form-data"in the input form.
I am also getting the file name in the request
corporate_id
"4"
Files
employee_list
array:5 [▼
"name" => "Employee1.xlsx"
"type" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
"tmp_name" => "/tmp/phpXboDe5"
"error" => 0
"size" => 8593
]
Please or to participate in this conversation.