Reputation: 3
I can assign Role to User within a team and can get team list attached to that user also can get list of Roles to same user, but when I put together to get the Role of each Team attached to that user in the Edit blade, the results get duplicated... My UserController:
public function edit(User $user)
{
$teams = Team::all();
$roles = Role::all();
return view('admin.users.edit', compact('user','roles','teams'));
}
my edit blade:
<table id="multi-select" class="display">
<thead>
<tr>
<th>
<label>
<input type="checkbox" class="select-all" />
<span></span>
</label>
</th>
<th>Customer/Team</th>
<th>Role</th>
<th>Description</th>
</tr>
</thead>
<tbody>
@foreach($user->rolesTeams as $team)
<tr>
<td>
<label>
<input type="checkbox" />
<span></span>
</label>
</td>
<td> {{ $team->display_name }}</td>
@foreach($user->roles as $role)
<td> {{ $role->display_name }}</td>
<td> {{ $role->description }}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
expected : Team Id 2 to display Role Id1 Team Id 3 to display Role Id 2 any help will be appreciated..
Upvotes: 0
Views: 1314
Reputation: 3
I figured it out by using for instead of foreach inside foreach loop,
@for ($i=0; $i<count ($user->rolesTeams) ; $i++)
<tr>
<td>
<label>
<input type="checkbox" />
<span></span>
</label>
</td>
<td> {{ $user->rolesTeams[$i]->display_name }}</td>
<td> {{ $user->roles[$i]->display_name }}</td>
<td> {{ $user->roles[$i]->description }}</td>
</tr>
@endfor
Upvotes: 0