我有一个带有管理员方面的laravel项目。我希望管理员可以访问注册用户。我在管理控制台上有一条名为“用户”的路由。单击该路由后,我要显示所有注册用户。请帮忙。
答案 0 :(得分:-1)
首先,创建一个控制器。 示例:-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>