I am working on laravel 5.2.I want to display those members who belongs to that particular group which is open at this time. Actually, i am getting all the members which i have stored in my database but, i only want to access or display only those members who belongs to a particular on which i am currently accessing. I am getting an error: Method groups does not exist. which is 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;"></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="">
<input class="form-control" type="text" name="addmember">
<button class="btn btn-primary" type="submit">Add</button>
<input type="hidden" name="_token" value="">
</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 as $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"></h5>
</section>
</section>
</div>
</section>
</div>
</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->hasMany('App\Grouptable');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire