我可以将角色分配给团队中的用户,并可以获得附加到该用户的团队列表,还可以获得同一用户的角色列表,但当我在编辑刀片中将每个团队的角色添加到该用户时,结果会重复...我的UserController:
public function edit(User $user)
{
$teams = Team::all();
$roles = Role::all();
return view('admin.users.edit', compact('user','roles','teams'));
}我的编辑刀片:
<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>期望: Team Id %2显示角色Id1 Team Id %3显示角色Id %2任何帮助都将不胜感激。
发布于 2020-10-10 19:11:07
我通过在foreach循环中使用for而不是foreach来解决这个问题,
@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>
@endforhttps://stackoverflow.com/questions/64292399
复制相似问题