I have 2 tables which users and groups and I also has created a pivot table for them. What I want to display is list of the group that user have not joined yet.
my controller
public function redirectFunct()
{
$user = User::find(Auth::user()->id);
$groups=Group::all();
$exists = DB::table('group_user')
->whereuser_id(Auth::user()->id)
->count() > 0;
return view('member.dashboard',['user'=>$user,'groups'=>$groups,'exists'=>$exists]);
}
blade file
@foreach($groups as $groups)
@if($!exists)
<tbody>
<tr>
<td>{{$groups->id}}</td>
<td>{{$groups->groupName}}</td>
<td>{{$groups->groupDesc}}</td>
<td><button type="button" >Details</button></td>
<td><a href="{{url('/join',$groups->id)}}"><button type="button" >Join</button></td>
</tr>
</tbody>
@endif
@endforeach
I do not sure how to check if the data is exist or not in the pivot table. Please help me.
CodePudding user response:
you could try this in your $exist
I'm not sure what ->count() > 0;
is use for
$exists = DB::table('Group')
->where('userID', Auth::user()->id)
->get();
If you want to display only the group that the user
doesn't exist in group
you could try this
<tbody>
@foreach($groups as $group)
@if('your group parent id' != 'your user id that related to the group')
<td>{{$group->id}}</td>
<td>{{$group->groupName}}</td>
<td>{{$group->groupDesc}}</td>
<td><button type="button" >Details</button></td>
<td><a href="{{url('/join',$groups->id)}}"><button type="button" >Join</button></td>
@endif
@endforeach
</tbody>
CodePudding user response:
this is the screenshot of that page
The pivot table