gaan10
226
8
Laravel

Add an array of data to the database

Posted 1 month ago by gaan10

Hi, I want to add an array consisting of multiple fields to my database. My controller method is :

$Patient_Name = $request->Patient_Name;
$Mobile = $request->Mobile;
$Surgeon = $request->Surgeon;
$Amount = $request->Amount;
     
     for($count = 0; $count < count($Patient_Name); $count++)
      {
       $data = array(
          'Patient_Name' => $Patient_Name[$count],
          'Mobile'  => $Mobile[$count],
          'Surgeon' => $Surgeon[$count],
          'Amount'  => $Amount[$count]
          );

          $insert_data[] = $data; 
      }
          
          hospital_incharge_referred::insert($insert_data);

Not able to pass data to the db. BTW I am passing the values to the controller via ajax.

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