Llamar a una función miembro getRealPath() en nulo
Quería preguntar cómo puedo poner un mensaje de error si no hay un archivo cargado pero presionan el botón de carga. ¿Cómo puedo poner un mensaje de error si getRealPath está vacío?
public function importExcel()
{
if (empty(Input::file('import_file')->getRealPath())) {
return back()->with('success','No file selected');
}
else {
$path = Input::file('import_file')->getRealPath();
$inserts = [];
Excel::load($path,function($reader) use (&$inserts)
{
foreach ($reader->toArray() as $rows){
foreach($rows as $row){
$inserts[] = ['biometrics' => $row['biometrics'], 'first_name' => $row['first_name'], 'last_name' => $row['last_name'], 'date' => $row['date'], 'emp_in' => $row['emp_in'], 'emp_out' => $row['emp_out']];
}
}
});
if (!empty($inserts)) {
DB::table('attendances')->insert($inserts);
return back()->with('success','Inserted Record successfully');
}
return back();
}
}
Mostrar la mejor respuesta