ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 1.路由 routes/web.php ``` <?php Route::namespace('Admin')->group(function () { Route::group(['middleware' => 'login'], function () { Route::match(['POST'], '/admindel', 'Admin@del'); }); }); ``` ## 2.管理员编辑 admin/admin/list.balde.php ```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> <!-- /Page Breadcrumb --> <!-- Page Body --> <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') //引入公共底部文件 <script> // 删除管理员 $('.admin-del').click(function () { var id=$(this).attr('dataid'); layer.confirm('确定删除吗?',{ title:'删除管理员', icon:3, },function (index) { layer.close(index); $.ajax({ url: "{{url('admindel')}}", type: 'post', data:{id:id}, dataType: 'json', success:function (data) { if (data.code == 1){ layer.msg(data.msg,{ icon:6, time:2000, },function () { location.href=data.url; }); }else { layer.open({ title:'删除失败', content:data.msg, icon:5, }); } } }); }); return false; }) </script> </body> <!-- /Body --> </html> ``` ## 3.控制器 Controller/admin/admin.php(del操作方法) ```php <?php namespace App\Http\Controllers\Admin; use App\Models\Admin as AdminModel; use App\Http\Controllers\Controller; class Admin extends Controller { // 删除管理员 public function del() { $adminInfo=AdminModel::find(request('id')); $res=$adminInfo->delete(); if ($res){ $msg=[ 'code'=>1, 'msg'=>'删除成功', 'url'=>url('admins') ]; }else{ $msg=[ 'code'=>1, 'msg'=>$res, ]; } return $msg; } } ```