php - Laravel 管理仪表板
问题描述
我有一个带有管理员端的 Laravel 项目。我希望管理员有权访问注册用户。我在管理仪表板上有一条名为 users 的路线。单击该路线时,我想显示所有注册用户。
任何帮助请..
解决方案
首先,制作一个控制器。示例:-UsersController
代码:-
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use DB;
class UsersController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$all_users = DB::table('users');
$all_users = $all_users->get();
return view('home')->with(['all_users' => $all_users]);
}
}
路线如下: -
Route::get('home', 'UsersController@index');
主页视图页面如下: -
<table class="table table-info table-hover">
<thead>
<tr class="table-primary">
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Username</th>
<th>Status</th>
<th>User Created At</th>
</tr>
</thead>
<tbody>
@foreach ($all_users as $users)
<tr>
<td>{{ $id_loop++ }}</td>
<td>{{ $users->name }}</td>
<td>{{ $users->email }}</td>
<td>{{ $users->username }}</td>
<td>
@if(Cache::has('user-is-online-' . $users->id))
<span class="text-success"><b>Online</b></span>
@else
<span class="text-secondary"><b>Offline</b></span>
@endif
</td>
<td>{{ $users->created_at }}</td>
</tr>
@endforeach
</tbody>
</table>
推荐阅读
- python - GitHub 工作流/自动化的 PyTest 和受控测试失败
- discord.py - 等待时间,然后 DM 与机器人,一次与多个用户
- amazon-web-services - 将网络负载均衡器与 ECS 动态端口映射配合使用
- python - 在 AWS ECS 上的服务 Auto Scaling 中注册可扩展目标时出错
- c - mkfifo() 创建文件出错
- python - 高斯图叠加
- html - 在vba selenium中循环没有id的无序列表
- flutter - How can I convert an Image selected from my gallery or camera snapshot from my flutter app to base64, display it before I persist to database
- java - 如何检查二维数组中的2个元素是否彼此相邻
- flutter - 如果对象不在数组中,则添加到数组