lundi 13 février 2017

Updating Pivot Table in laravel 5.3

Vote count: 0

I am new at laravel. Currently i am using laravel-5.3. I am having some issues to updating the tables. Suppose i have two modles(Research and Member). Both have many-to-many relations. I have a pivot table named member_research. This table hase the following columns.

  1. research_id
  2. member_id
  3. role

So when i am trying to update some research i might have to update the research members and their roles too along with other info. I am actually trying the following way:

$Research = Researches::find($request->id);
$Research->Member->all();

            foreach ($Research->member as $id){
                $id->pivot->role = $role ;
                $id->pivot->save();
            }

in this approach the role is updating finely. but when i am trying to update the member_id it is not working. Here is the code

$Research = Researches::find($request->id);
$Research->Member->all();

            foreach ($Research->member as $id){
                $id->pivot->member_id = $new_id ;
                $id->pivot->save();
            }

can anyone help me?

asked 39 secs ago

Let's block ads! (Why?)



Updating Pivot Table in laravel 5.3

Aucun commentaire:

Enregistrer un commentaire