我正在laravel 5.3开发一个项目。我在数据库中使用users
表和points
表的地方。用户与积分交易相关联。这些横断面记录在points
表中。我的points
表在我之前的问题中看起来像是这样的链接
- I want to get user id in laravel 5.3 controller with Auth::user()->id but it creates error their -
。现在我正在获取用户在页面中的所有数据whare我想显示那里的净余额。你可以在图片中看到结果。image is here
所以目前我在控制器中使用以下代码。
public function users_list()
{
$ptitle = "Website Users";
$pdesc = "";
//$total_users = User::count();
$users = User::select('*')->orderby('created_at', 'desc')->get();
return view('admin.all-users-list',
['ptitle' => $ptitle,
'pdesc' => $pdesc,
'users' => $users,
'total_users' => $this->total_users,
]);
}
获得结果如下所示
<table class="table table-hover">
<tbody><tr>
<th>ID</th>
<th>User Name</th>
<th>Email</th>
<th>Country</th>
<th>Date</th>
<th>Points</th>
</tr>
<?php foreach ( $users as $u ){ ?>
<tr>
<td>{{ $u->id }}</td>
<td>{{ $u->user_name }}</td>
<td>{{ $u->email }}</td>
<td>{{ $u->country }}</td>
<td>{{ $u->created_at }}</td>
<td></td>
</tr>
<?php }?>
</tbody></table>
但我不知道如何在查询构建器中创建连接以获取列表中每个用户的网点