0

I want to import a csv file containing large data but If i want to import It says undefined index even if I already configured the headers already in my controller. And I want to break down the address column into parts as you can see i got 5 columns named unitname, block,street,level,stack. My addres column example is like this 261 River Valley Road #09-21 which is 261 is block, River Valley is street, #09 is level, 21 is stack and unitname is #09-21 . transtype is static value. Can someone know how could I fix this? Thanks

error I got Undefined index: Project Name

CSV sample here https://gofile.io/?c=XLUclQ

My controller

public function import(Request $request)
    {
        if($request->hasFile('template')){
            $path = $request->file('template')->getRealPath();
            $data = \Excel::load($path)->get();
            if($data->count() > 0){
                $rows = $data->toArray();
                // dd($rows);
                foreach ($rows as $row) {
                    $inserts[]=[
                        'transtype' => 'RESI',
                        'project_name' => $row['Project Name'],
                        'unitname' => $row['Address'],
                        'block' => $row['Address'],
                        'street' => $row['Address'],
                        'level' => $row['Address'],
                        'stack' => $row['Address'],
                        'no_of_units' => $row['No. of Units'],
                        'area' => $row['Area (sqm)'],
                        'type_of_area' => $row['Type of Area'],
                        'transacted_price' => $row['Transacted Price ($)'],
                        'nettprice' => $row['Nett Price($)'],
                        'unitprice_psm' => $row['Unit Price ($ psm)'],
                        'unitprice_psf' => $row['Unit Price ($ psf)'],
                        'sale_date' => $row['Sale Date'],
                        'contract_date' => $row['Sale Date'],
                        'property_type' => $row['Property Type'],
                        'tenture' => $row['Tenure'],
                        'completion_date' => $row['Completion Date'],
                        'type_of_sale' => $row['Type of Sale'],
                        'purchaser_address_indicator' => $row['Purchaser Address Indicator'],
                        'postal_district' => $row['Postal District'],
                        'postal_sector' => $row['Postal Sector'],
                        'postal_code' => $row['Postal Code'],
                        'planning_region' => $row['Planning Region'],
                        'planning_area' => $row['Planning Area'],
                    ];
                }

            }

            if(empty($inserts)){
                dd('Request data does not have any files to import.');  
            }
            else {
                \DB::table('xp_pn_ura_transactions')->insert($inserts);
                dd('record inserted');  
            }

        }
    }

0 Answers0