0

Can I ask the question to how to insert the multiple data or information in database using foreach at the controller?

Robocop Cop
  • 23
  • 2
  • 6

1 Answers1

0
$data = [];

$period = CarbonPeriod::create('2020-09-10', '2020-09-20')->toArray();

foreach ($period as $key => $value) {

$row['register_date'] = $value->format('Y-m-d');
array_push($data, $row);
}

User::insert($data);
Asim Raza
  • 80
  • 4
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. [From Review](/review/low-quality-posts/27114153) – double-beep Sep 08 '20 at 08:07