как я могу получить имя пользователя, у которого тот же проект, в который вошел пользователь. Используйте Laravel и отношение многие ко многим.В сводной таблице user_projects есть user_id и project_id.
это мой контроллер
public function index()
{
$users = User::where('id', Auth::user()->id)->with('projects')->get();
return view ('teams.index', compact('users'));
}
это мой индекс просмотра
<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>




, но когда проект не добавлен, представление пустое.