jeudi 18 janvier 2018

Laravel: How to update pivot tables withou using first

Im new in Laravel. I want to update my leaves pivot table. I am trying with below code but it only updates the single row i have multiple rows in db with same leave_id and i want to update all this where leave_id = xyz

I have following function in my model Leave:

public function relLeave(){

    return $this->belongsToMany(User::class)->withPivot('days');

}

LeaveController:

public function saveUpdate(Request $request)
{
  $leave = Leave::find($request->id);
  $msg = $leave->relLeave()->Where('leave_id', $request->id)->get()->first();
 $msg->pivot->days = $request->days;
 $msg->pivot->save();
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mL9Lng
via IFTTT

Aucun commentaire:

Enregistrer un commentaire