多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 1.路由 routes/web.php ```php Route::namespace('Admin')->group(function () { Route::group(['middleware' => 'login'], function () { Route::match(['GET'], '/admins', 'Admin@list'); }); }); ``` ## 2.管理员列表 admin/admin/list.balde.php ![](https://i.vgy.me/bFhFup.png) ```html @include('admin.public.head') //引入公共头部文件 <div class="main-container container-fluid"> <div class="page-container"> @include('admin.public.left') <div class="page-content"> <div class="page-breadcrumbs"> <ul class="breadcrumb"> <li class="active"> <i class="fa fa-home"></i>&nbsp;管理员管理 </li> <li>管理员列表</li> </ul> </div> <div class="page-body"> <a href="{{url('Add')}}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;管理员添加</a> <div class="row"> <div class="col-xs-12"> <div class="widget"> <div class="widget-header"> <span class="widget-caption">管理员列表</span> </div> <div class="widget-body"> <table class="table table-hover table-bordered"> <thead> <tr> <th>ID</th> <th>用户名</th> <th>昵称</th> <th>邮箱</th> <th>权限</th> <th>状态</th> <th>操作</th> </tr> </thead> <tbody> @foreach ($adminRes as $vo) <tr> <td align="center">{{$vo->id}}</td> <td>{{$vo->username}}</td> <td>{{$vo->nickname}}</td> <td>{{$vo->email}}</td> <td> @if ($vo->is_super == 1) <span style="color: red;font-weight: bold">超级管理员</span> @else 普通管理员 @endif </td> <td align="center"> @if ($vo->status == 1) <input type="button" class="btn btn-success btn-xs" value="正常"> @else <input type="button" class="btn btn-danger btn-xs" value="已禁用"> @endif </td> <td> @if (session('admin.is_super') == 1) @if ($vo->is_super != 1) @if ($vo->status == 1) <a href="#" class="btn btn-warning btn-xs admin-status" dataid="{{$vo->id}}" status=""{{$vo->status}}>禁用</a> @else <a href="#" class="btn btn-success btn-xs admin-status" dataid="{{$vo->id}}" status=""{{$vo->status}} >启用</a> @endif @endif @endif @if ($vo->is_super == 1) <a href="{{url('adminedit',['id'=>$vo->id])}}" class="btn btn-azure btn-xs disabled">编辑</a> <a href="#" class="btn btn-danger btn-xs admin-del disabled" dataid="{{$vo->id}}">删除</a> @else <a href="{{url('adminedit',['id'=>$vo->id])}}" class="btn btn-azure btn-xs ">编辑</a> <a href="#" class="btn btn-danger btn-xs admin-del " dataid="{{$vo->id}}">删除</a> @endif </td> </tr> @endforeach </tbody> </table> {{$adminRes->links()}} //分页输出 </div> </div> </div> </div> </div> </div> </div> </div> @include('admin.public._js') //引入公共Js部分 </body> </html> ``` ## 3.控制器 Controller/admin/admin.php(list操作方法) ```php <?php namespace App\Http\Controllers\Admin; use App\Models\Admin as AdminModel; use App\Http\Controllers\Controller; class Admin extends Controller { //管理员列表 public function list() { $adminRes=AdminModel::orderBy('is_super','desc')->orderBy('status')->paginate(10); $viewData=[ 'adminRes'=>$adminRes ]; return view('admin.admin.list',$viewData); } } ``` ## 4.模型 Models/Admin.php(list方法) ```php <?php namespace App\Models; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Validator; use Illuminate\Database\Eloquent\Model; class Admin extends Model { } ```