1

i have form to make a bill for multiple products, that form return request like this

  #parameters: array:5 [▼

  "quantity" => array:2 [▼
    0 => "1"
    1 => "2"
  ]
  "product" => array:2 [▼
    0 => "Mr. Jasen Beer,OliveDrab,XS"
    1 => "Carlotta Yundt"
  ]
  "date" => array:2 [▼
    0 => "2019-12-29"
    1 => "2019-12-29"
  ]
  "id" => array:2 [▼
    0 => "15"
    1 => "11"
  ]
]
}

i need to loop all arrays to make insert all at once thanks.

1 Answer 1

2

Try to loop it like this, you will get the array wrap every product's attributes:

$inserted_array = [];

foreach($parameters as $key => $values) {
    foreach($values as $index => $val) {
         $inserted_array[$index][$key] = $val;
    }
}

\DB::table('table_name')->insert($inserted_array);

And I found that there is id in your array, remember to make it fillable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.