首页 > 解决方案 > Laravel 管理仪表板

问题描述

我有一个带有管理员端的 Laravel 项目。我希望管理员有权访问注册用户。我在管理仪表板上有一条名为 users 的路线。单击该路线时,我想显示所有注册用户。

任何帮助请..

标签: phplaravel

解决方案


首先,制作一个控制器。示例:-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>

推荐阅读