Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mikiobryant's avatar

Mass database update from array

Hello,

I'm trying to update database fields based on excel import. I get the right data from excel, now I can't get it to update the database table on these three fields with these four conditions. It seems to go well, but nothing is updated.

Here is my code:


public function importExcelCall()
    {

            if(Input::hasFile('import_file')){

            $path = Input::file('import_file')->getRealPath();
            $data = Excel::load($path, function($reader) {
            })->get();


               foreach ($data as $key => $value) 
                {                       
                            $update = ['montage' => $value->montage, 'vereinbarung' => $value->vereinbarung, 'kommentar' => $value->kommentar]; 
                               
                           owpmontagecallcenter::where('TZIP', $value->tzip)->where('HOUSENO', $value->houseno)->where('SUPPL', $value->suppl)->where('UNIT', $value->unit)->update($update);            
                }

                    return redirect('owpmontagecallcenter')->with('status', 'Done.');

                }
                 return redirect()->back()->with('status', 'Something.');

    }

Can you help me?

0 likes
3 replies
jlrdw's avatar

Try casting to the correct type.

ejdelmonico's avatar

Are you using protected $guarded = []; or something like it? What is the error message. I would dd($update); to check the array for the correct key/value pairs.

Mikiobryant's avatar

I used dd($update), the values were ok.

I found out that there are empty cells, field 'SUPPL' in excel is sometimes null sometimes one character. When I remove from where ('SUPPL', $value->suppl), values are updated.

But there is still problem, how to still check if ('SUPPL', $value->suppl) in where clause?

Please or to participate in this conversation.