2016-10-05 53 views
0

我試圖檢索多行,循環用foreach,和更新每一個特定值的那些行(基於開關)通過的foreach更新有着不同的價值觀多行 - Laravel雄辯

我得到的Method save does not exist錯誤。不知道這個使用Eloquent的語法應該是什麼。

$appointmentreminders = Appointmentreminder::where('appointment_id', '=', $id)->get(); 

foreach ($appointmentreminders as $appointmentreminder) 
{ 
      switch ($appointmentreminder->timeunit) { 
       case "minute": 
        $reminder = clone($appointment->appointment_start); 
        $reminder->subMinutes($appointmentreminder->time); 
        break; 

       case "hour": 
        $reminder = clone($appointment->appointment_start); 
        $reminder->subHours($appointmentreminder->time); 
        break; 

       case "day": 
        $reminder = clone($appointment->appointment_start); 
        $reminder->subDays($appointmentreminder->time); 
        break; 

       case "week": 
        $reminder = clone($appointment->appointment_start); 
        $reminder->subWeeks($appointmentreminder->time); 
        break; 

       case "month": 
        $reminder = clone($appointment->appointment_start); 
        $reminder->subMonths($appointmentreminder->time); 
        break; 
      } 

      $appointmentreminders->reminder = $reminder; 
      $appointmentreminders->save(); 
} 

回答

0

做這樣

$appointmentreminders = Appointmentreminder::where('appointment_id', '=', $id)->get(); 

foreach ($appointmentreminders as $appointmentreminder) 
{ 
    $appointmentreminder = Appointmentreminder::find($appointmentreminder->id); 
    switch ($appointmentreminder->timeunit) { 
    case "minute": 
     $reminder = clone($appointment->appointment_start); 
     $reminder->subMinutes($appointmentreminder->time); 
     break; 

    case "hour": 
     $reminder = clone($appointment->appointment_start); 
     $reminder->subHours($appointmentreminder->time); 
     break; 

    case "day": 
     $reminder = clone($appointment->appointment_start); 
     $reminder->subDays($appointmentreminder->time); 
     break; 

    case "week": 
     $reminder = clone($appointment->appointment_start); 
     $reminder->subWeeks($appointmentreminder->time); 
     break; 

    case "month": 
     $reminder = clone($appointment->appointment_start); 
     $reminder->subMonths($appointmentreminder->time); 
     break; 
    } 

    $appointmentreminder->reminder = $reminder; 
    $appointmentreminder->save(); 
} 
+0

完美的作品!謝謝@Komal – user3489502

+0

歡迎:)感謝您接受我的答案 – Komal