我有一个laravel项目,有一个管理员端。我希望管理员可以访问注册用户。我在管理面板上有一个叫做用户的路由. 当该路由被点击时,我想显示所有注册用户。任何帮助,请...
首先,做一个controller.example: - 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>