Я хочу отобразить имя пользователя, у которого есть один проект с вошедшим пользователем. Используйте таблицу отношений user_id и project_id в UserProject в качестве сводной таблицы.
мой контроллер индекса
public function index()
{
$users = User::with('projects')->get();
return view ('teams.index', compact('users', 'project'));
}
мой индекс просмотра
<table class="table table-consended">
<tr>
<th> <h4>No</h4> </th>
<th> <h4>Name</h4> </th>
<th> <h4>Role</h4> </th>
<th> <h4>Project</h4> </th>
</tr>
@foreach($users as $item => $user)
<tr>
<td>{{$item+1}}</td>
<td>{{$user->name}}</td>
<td>{{$user->role->name}}</td>
<td>
@foreach ($user->projects as $project)
{{$project->project_name}}
@endforeach
</td>
</tr>
@endforeach()
</table>
, когда я пытаюсь это сделать, имя пользователяотображаются в индексе, хотя это не в том же проекте.![index blade](https://i.stack.imgur.com/lzjzu.png)