php - Method groups does not exist error in Laravel 5.2 -
i working on laravel 5.2.i want display members belongs particular group open @ time. actually, getting members have stored in database but, want access or display members belongs particular on accessing. getting error: method groups not exist. shown below:
my controller:
public function members($id){ $dashes=grouptable::findorfail($id); $members=member::all(); return view('members' , ['dashes'=>$dashes,'members'=>$members]); } public function dashboard($id){ $dashes=grouptable::findorfail($id); return view('dashboard' , ['dashes'=>$dashes]); } public function addmembers(request $request){ $member=new member(); $member->members=$request['addmember']; $request->groups()->members()->save($member); return redirect()->back(); }
my view:
<body> <div class="row"> <div class="col-lg-3 col-lg-offset-1"> <img src="images/imgresponsive_placeholder.png" class="img-circle img- responsive" alt="placeholder image"> </div> <div class="col-lg-7"> <h1 style="color:black;">{{ $dashes->name }}</h1></div> <br /> </div> <div class="row"> <div class="col-lg-3"> <button class="btn btn-success" onclick="myfunction()"> add members + </button> <div> <form id="demo" style="display:none;" method="post" action="{{ route('addmember') }}"> <input class="form-control" type="text" name="addmember"> <button class="btn btn-primary" type="submit">add</button> <input type="hidden" name="_token" value="{{ session::token() }}"> </form> </div> </div> <div class="col-lg-7 col-lg-offset-0"> <div class="panel panel-default"> <div id="grp" class="panel-heading"> <h3 id="grouptitle" class="panel-title">group members</h3> </div> <div id="zx" class="panel-content"> <div class="row"> @foreach($members $member) <section class="col-md-6"> <div class="row"> <section class="col-md-offset-1 col-md-3 col-xs-offset-1 col-xs-4"> <img id="imagesize" src="images/g.jpg" class="img-circle"/> </section> <section class="col-md-offset-1 col-md-7 col-xs-7"> <section class="col-md-12"> <h5 id="friendname">{{$member->members}}</h5> </section> <section class="col-md-12"> <button type="button" class="btn btn-sm btn- default">score</button> </section> </section> </div> <div class="row"> <section class="col-md-offset-9 col-md-3 col-xs-offset-6 col-xs-4"> <div class="btn-group"> <button id="btnclr1" type="button" class="btn btn-block btn-warning dropdown-toggle" data-toggle="dropdown" aria- expanded="false"><span class="caret"></span></button> <ul id="bckdrp" class="dropdown-menu" role="menu"> <li role="presentation"><a id="drpmenu" href="#">remove</a> </li> </ul> </div> </section> </div> <div class="row"> <section class="col-md-offset-1 col-md-10"> <hr> </section> </section> @endforeach </div> <div id="mn" class="panel-footer"><a id="seemr1" href="#.html">see more</a></div> </div> </div> </div> </div> </div> </div> </div> </body>
my routes:
route::get('/members/{id}',[ 'uses'=>'groupcontroller@members', 'as'=>'members' ]); route::get('/dashboard/{id}',[ 'uses'=>'groupcontroller@dashboard', 'as'=>'dashboard' ]); route::post('/memeber/add',[ 'uses'=>'groupcontroller@addmembers', 'as'=>'addmember' ]);
my modals:
grouptable: public function members(){ return $this->hasmany('app\member'); } member: public function groups(){ return $this->belongsto('app\grouptable'); }
i not quite understand entire problem, but
public function addmembers(request $request){ $member=new member(); $member->members=$request['addmember']; $request->groups()->members()->save($member); return redirect()->back(); }
should more like
public function addmembers(request $request){ $member=new member(); $member->propertyx = $request->get('propertyx'); $member->propertyy = $request->get('propertyy'); $member->groups()->attach($group); // many-to-many (n-n) relation $member->groups()->associate($group); // one-to-many (1-n) relation $member->save(); return redirect()->back(); }
depending on migrations should choose attach() or associate()
Comments
Post a Comment