0

I have a users' table and another table for their respective plans.I have a form that displays the users and their plans. I want a HR officer to be able to enter his/remarks to all plans and save all by a single submit button. Please help on how to refactor this code.

public function submitHrRemarks(Request $request){

    foreach ($plan_id = $request->plan_id as $key => $value) {

        if ($plan_id[$key] != '') {
      
            $hr_remarks = $request->hr_remarks[$key];
            
           // dd($hr_remarks,$value);

            $query = DB::table("weekly_plans")
                ->updateOrInsert(
                    [
                        'id' => $plan_id[$key], // pass your update id else empty
                    ],
                    //   $data =
                    [
                        'id' => $value,
                        'hr_remarks' => $hr_remarks,
                    ]);
        }
    }

    flash('You have successfully submitted the remarks!');
    return back();
}

This image is the form showing users and their plans,also a HR officer can enter remarks

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

1 Answers1

0

You can check answer there

Eloquent model mass update

Some time ago I researched this question and I came to the conclusion that cycle + query builder is the best option for mass update

MTakumi
  • 320
  • 2
  • 10