letters); $days = count($letters); for($i=0; $i<$days; $i++){ $now = date('N'); $row->first_delivery = $this->getNextDate($row->first_delivery); $date = $this->getEventDate($row->first_delivery, "+". ($i)*$row->period_val ." days"); $event = new \eventInfo(); $event->customer_id = $customer_id; $event->event_id = $letters[$i]; $event->next_delivery = $date; $event->project_id = $project_id; $event->event_trigger = 'series_of_letter'; $event->save(); } } } private function getEventDate($first_delivery,$time){ $now = date("Y-m-d"); $EmailDate = new \DateTime($first_delivery); $EmailDate->modify($time); return $EmailDate->format('Y-m-d'); } function getNextDate($day) { $ret = false; for ($i=1; $i<=7; $i++) { if (date('w',strtotime('+'.$i.' day'))==$day) { $ret = date('Y-m-d',strtotime('+'.$i.' day')); break; } } return $ret; } }