mardi 3 avril 2018

Call to a member function getRealPath() on null

I wanted to ask on how can i put a error message if theres no uploaded file but they press the upload button. How can I put an error message if the getRealPath is empty?

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();
        }

    }



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Iu2wt9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire