How to update a pivot table using Eloquent in laravel 5

前端 未结 5 2000
攒了一身酷
攒了一身酷 2020-12-06 09:16

I am new to laravel. I am working on a laravel 5 app and I am stuck here. I have 2 models as such:

class Message extends Eloquent{

    public function user(         


        
5条回答
  •  鱼传尺愫
    2020-12-06 09:41

    Here is a small example of how to update the pivot table column

        $query = Classes::query();
        $query = $query->with('trainees')
                       ->where('user_id', Auth::id())
                       ->find($input['classId']);
    
        foreach ($query->trainees as $trainee) {
           $trainee->pivot->status = 1 //your column;
           $trainee->pivot->save();
        }
    

    Note: make sure your relation data must in an array Hope its help you :) happy coding

提交回复
热议问题