Van1310
5 months ago

import csv file into database without database matching fields

Posted 5 months ago by Van1310

csv file controller

if($request->hasFile('import_file')){

$path = $request->file('import_file')->getRealPath();
    
$data = Excel::load($path, function($reader){})->get();
    
    if(!empty($data) && $data->count())
    
    {
    
        foreach ($data as $key => $value) {
    
            $import = new Registration();                   
    
            $import->city=$value->city;
    
            $import->student_name=$value->student_name;
    
            $import->contact_number=$value->contact_number;
    
            $import->stream_name=$value->stream_name;
    
            $import->reference_name=$value->reference_name;
    
            $import->email=$value->email;
    
            $import->date_registration=$value->date_registration;
    
            $import->save();
    
        }
                flash('File Upload Successfully')->success();

                return \Redirect::back();

            }
    

}

Database fields (student_name,contact_no etc...) i want some extra fields in submit using import file in laravel

Please sign in or create an account to participate in this conversation.