循环数组并保存在数据库中的多个记录Laravel php

I have a multi-select option and a function which i want it to loop through the array and pick one value and save in database one at a time, but now its saving the last item in the database. e.g. if someone selects five items at one the records entered in DB should be 5 records

Code

$kycs = json_decode($input['document_type_ids']);

foreach($kycs as $key => $kyc){
  $input['kyc_type'] = CheckList::find($kyc)->slug;

  $filledDocument->payload = json_encode($input);

  $filledDocument->save();
}

i have used the both version of foreach i.e.

foreach($kycs as $kyc)  && oreach($kycs as $key => $kyc)

where am i going wrong....thanks in advance

i did manage to get help from laracast...

 foreach($kycs as $key => $kyc){
   $filledDocument = new ClientFilledInvestmentApplicationDocument();  
 }

i have to create an instance of the $fileDocument within the loop...

https://laracasts.com/discuss/channels/eloquent/save-method-only-writing-last-record-in-foreach-loop?page=1

You need to create the instance of $filledDocument inside the foreach loop, for example:

foreach($kycs as $key => $kyc){
  $input['kyc_type'] = CheckList::find($kyc)->slug;
  $filledDocument = new FilledDocument(); // replace with your model here
  $filledDocument->payload = json_encode($input);
  $filledDocument->save();
}