我想列出最近 5 天内注册的用户。要列出所有用户 1,请使用以下查询。
$users = User::select('*')->orderby('created_at', 'desc')->get();
并像这样在 View 中获取它。
<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>{{ \App\Points::getUserPoints($u->id) }}</td>
</tr>
<?php }?>
</tbody></table>
但是获取过去 5 天内注册的用户的查询是什么..?任何人请告诉我一个好的查询..
最佳答案
$now = Carbon::now();
$users = User::where('created_at', '>=', $now->subDays(5))->get();
确保“use Carbon\Carbon;
”位于文件顶部。
关于php - 如何在 Laravel 5.3 中的查询生成器中使用时间戳来跟踪最近 5 天注册的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42341981/