一、使用phpStorm创建laravel项目
参考:https://www.jianshu.com/p/0941dcfc939a
1、使用Composer创建项目
2、选择composer.phar所在目录
3、添加php可执行文件
4、创建中
二、创建网站
1、使用小皮软件创建网站
2、查看效果
三、登录 数据表
1、新建数据库
2、链接数据库
3、使用sql建表、填充数据
#【新建】管理员表
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(250) NOT NULL DEFAULT '',
`password` varchar(250) NOT NULL DEFAULT '',
`ispasswd` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否第一次登陆0是,1否',
`avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '头像',
`gid` int(11) NOT NULL DEFAULT '0',
`real_name` varchar(250) NOT NULL DEFAULT '',
`phone` varchar(50) NOT NULL DEFAULT '',
`lastlogin` int(11) NOT NULL DEFAULT '0',
`add_time` int(10) NOT NULL DEFAULT '0',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否禁用,0正常1禁用',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;
#【插入】管理员表添加数据(admin-654321 admin222-123456)
INSERT INTO `admin` VALUES ('1', 'admin', '$2y$10$EWEAN2vfBCNINO97elISIOc/.PWnbEOS8ihfOpABmsOG.YXPwdiaG', '2', '', '1', '张三', '', '1604212223', '1515154827', '0');
INSERT INTO `admin` VALUES ('7', 'test', '$2y$10$EWEAN2vfBCNINO97elISIOc/.PWnbEOS8ihfOpABmsOG.YXPwdiaG', '2', '', '10', '张五五', '', '0', '1543409778', '0');
INSERT INTO `admin` VALUES ('23', 'aaccdd', '$2y$10$UwJYnTFHEoZVSjc0PhGMeOQUFNrsOKdAihTWmr4fgeZqfbJFPoN4u', '0', '', '7', '测试用户', '', '0', '0', '1');
INSERT INTO `admin` VALUES ('28', 'admin222', '$2y$10$4JqE/D5WdzfhtcSSlgVpoe89EetGcXy.9NCM/jaAkX9CV9mDZ4Acu', '0', '', '7', '', '', '0', '0', '0');
四、登录模块
1、添加资源文件
layui.rar
下载资源解压后放到项目publish目录下static文件夹下
2、添加验证码插件
composer require gregwar/captcha
3、创建 视图模板 文件
4、编辑 视图模板 文件
resources/views/admins/account/login.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>后台登录</title>
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
<script type="text/javascript" src="/static/layui/layui.js"></script>
</head>
<body style="background:#1E9FFF">
<div
style="position: absolute;left: 50%;margin-left: -240px;width:480px;height:300px;margin-top: 200px;background-color: #fff;border-radius: 4px;box-shadow: 5px 5px 20px #444;padding:10px">
<p style="font-size: 22px;color:#555;text-align: center;margin:15px 0px">XX后台管理系统</p>
<hr>
<div class="layui-form">
@csrf
<div class="layui-form-item">
<label class="layui-form-label">用户名</label>
<div class="layui-input-inline">
<input type="text" class="layui-input" name="username" placeholder="请填写用户名">
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">密码</label>
<div class="layui-input-inline">
<input type="password" class="layui-input" name="pwd" placeholder="请填写密码">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">验证码</label>
<div class="layui-input-inline" style="width:60px;">
<input type="text" class="layui-input" name="vericode">
</div>
<img name="img_vericode" src="/admins/account/captcha"
style="height:36px;border:1px solid black; cursor:pointer;" onclick="changeImg()"/>
</div>
<div class="layui-input-block">
<button class="layui-btn" onclick="doLogin()">登录</button>
</div>
</div>
</div>
<script>
layui.use(['layer'], function () {
$ = layui.jquery;
layer = layui.layer;
changeImg();//等框架加载完再调用方法
});
/**
* 更新验证码1
*/
function changeImg() {
var url = '/admins/account/captcha?adf=' + Math.random();
$('img[name="img_vericode"]').attr('src', url);
}
/**
* 去登录
*/
function doLogin() {
const username = $('input[name="username"]').val();
const pwd = $('input[name="pwd"]').val();
const vericode = $('input[name="vericode"]').val();
const _token = $('input[name="_token"]').val();
if (username == '') {
return layer.alert('请填写用户名', {icon: 2});
}
if (pwd == '') {
return layer.alert('请填写密码', {icon: 2});
}
if (vericode == '') {
return layer.alert('请填写验证码', {icon: 2});
}
$.post('/admins/account/dologin', {
username: username,
pwd: pwd,
vericode: vericode,
_token: _token
}, function (res) {
if (res.code > 0) {
return layer.alert(res.msg, {icon: 2});
}
layer.msg(res.msg);
setTimeout(function () {
window.location.href = '/admins/home/index';
}, 1000);
}, 'json');
}
</script>
</body>
</html>
5、修改用户模型
app/Models/User.php
protected $table='admin';//更新用户表名
6、创建 控制器
app/Http/Controllers/admins/Account.php
<?php
namespace App\Http\Controllers\admins;
use App\Http\Controllers\Controller;
use Gregwar\Captcha\CaptchaBuilder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
/**
* 后台账号
* Class Account
* @package App\Http\Controllers\admins
*/
class Account extends Controller {
/**
* 登录
*/
public function login() {
return view('/admins/account/login');
}
/**
* 生成验证码
*/
public function captcha() {
//实例化验证码类
$builder = new CaptchaBuilder;
$builder->build();
session_start();//开启session
$_SESSION['phrase'] = $builder->getPhrase();
header('Content-type: image/jpeg');//生成到页面
$builder->output();
}
//处理登录
public function doLogin(Request $req) {
$username = $req->username;
$pwd = $req->pwd;
$verICode = $req->vericode;
if ($username == '') {
return json_encode(array('code' => 1, 'msg' => '用户名不能为空'));
}
if ($pwd == '') {
return json_encode(array('code' => 1, 'msg' => '密码不能为空'));
}
if ($verICode == '') {
return json_encode(array('code' => 1, 'msg' => '验证码不能为空'));
}
session_start();
if (strtolower($_SESSION['phrase']) != strtolower($verICode)) {
return json_encode(array('code' => 1, 'msg' => '验证码不正确'));
}
//验证用户
$res = Auth::attempt(['username' => $username, 'password' => $pwd]);
if (!$res) {
return json_encode(array('code' => 1, 'msg' => '用户名或密码错误'));
}
//更新登录时间
DB::table('admin')->where('username', $username)->update(array('lastlogin' => time()));
return json_encode(array('code' => 0, 'msg' => '登录成功'));
}
//退出登录
public function logout() {
Auth::logout();
return json_encode(array('code' => 0, 'msg' => '退出登录成功'));
}
}
7、注册路由
routes/web.php
use App\Http\Controllers\admins\Account;
//name定义路由名称 login:laravel默认登录路由名称
Route::get('/admins/account/login', [Account::class, 'login'])->name('login');
//验证码
Route::get('/admins/account/captcha', [Account::class,'captcha']);
//处理登录
Route::post('/admins/account/dologin',[Account::class,'doLogin']);
//注销
Route::get('/admins/account/logout', [Account::class, 'logout']);
8、解决问题
http://renwushizhan1/admins/account/login
【解决】添加伪静态
public/.htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
9、查看效果
http://renwushizhan1/admins/account/login
登录界面
登录成功后:
五、中间件
1、创建中间件文件
使用中间件进行权限验证
app/Http/Middleware/Rightvalidate.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
/**
* 权限验证中间件
* Class Rightvalidate
* @package App\Http\Middleware
*/
class Rightvalidate {
public function handle($request, Closure $next) {
$admin = Auth::user();
$gid = (int)$admin->gid;
$group = DB::table('admin_group')->where('gid', $gid)->item();
if (!$group) {
return $this->_norights($request, '该角色不存在');
}
$rights = [];
if ($group['rights']) {
$rights = json_decode($group['rights'], true);
}
//当前访问的是哪个菜单?(读取访问路由信息)
$res = $request->route()->action['controller'];//App\Http\Controllers\admins\Home@index
$res = explode('\\', $res);
$res = array_pop($res);//Home@index
$res = explode('@', $res);
//当前url对应的菜单
$cur_menu = DB::table('admin_menu')->where('controller', $res[0])->where('action', $res[1])->where('isdel', 0)->item();
if (!$cur_menu) {
return $this->_norights($request, '该功能不存在');
}
if ($cur_menu['status'] == 1) {
return $this->_norights($request, '该功能已被禁用');
}
//判断一下该菜单的mid在不在$rights数组中
if (!in_array($cur_menu['mid'], $rights)) {
return $this->_norights($request, '权限不足');
}
$admin->group_title = $group['title'];
$admin->rights = $rights;
$request->admin = $admin;
return $next($request);
}
//封装
private function _norights($request, $msg) {
if ($request->ajax()) {
return response(json_encode(array('code' => 1, 'msg' => $msg)));
}
return response($msg);
}
}
2、注册中间件
app/Http/Kernel.php
//权限验证中间件
'rights'=>\App\Http\Middleware\Rightvalidate::class,
六、提供者
1、创建提供者文件
app/Providers/DBServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\ServiceProvider;
/**
* 数据库服务提供者
* Class DBServiceProvider
* @package App\Providers
*/
class DBServiceProvider extends ServiceProvider {
/**
* 内置函数,系统调用
*/
public function boot() {
//查询一条记录 注入名为item的函数
QueryBuilder::macro('item', function () {
$data = $this->first();
return $data ? (array)$data : false;
});
}
}
2、注册提供者
config/app.php
//扩展DBServiceProvider
App\Providers\DBServiceProvider::class,
七、首页 数据表
#【新建】 人员分组表
DROP TABLE IF EXISTS `admin_group`;
CREATE TABLE `admin_group` (
`gid` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`rights` text NOT NULL,
PRIMARY KEY (`gid`)
) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
#【插入】 人员分组表
INSERT INTO `admin_group` VALUES ('1', '开发人员', '[3,4,18,5,6,7,167,10,11,12,13,14,152,153,155,166,168,15,17,62,84,120,121,102,116,122,123,124,125,128,129,130,162,174,175,126,127,131,132,133,134,135,136,137,165,138,139,140,141,142,143,144,145,146,147,148,149,160,169,170,176]');
INSERT INTO `admin_group` VALUES ('7', '系统管理员', '[3,4,18,5,6,7,8,13,14,152]');
INSERT INTO `admin_group` VALUES ('10', '客服人员', '[3,4,18,5,6,7,8,11,12,13,153,155,15,17,62,84]');
#【新建】菜单表
DROP TABLE IF EXISTS `admin_menu`;
CREATE TABLE `admin_menu` (
`mid` int(11) NOT NULL AUTO_INCREMENT,
`pid` int(11) NOT NULL DEFAULT '0' COMMENT '上级菜单',
`ishidden` tinyint(1) NOT NULL COMMENT '隐藏菜单',
`ord` smallint(6) NOT NULL DEFAULT '0' COMMENT '排序',
`status` tinyint(1) NOT NULL COMMENT '状态:0启用,1禁用',
`icon` varchar(50) NOT NULL DEFAULT '',
`title` varchar(250) NOT NULL COMMENT '名称',
`controller` varchar(20) NOT NULL DEFAULT '' COMMENT '操作',
`action` varchar(20) NOT NULL DEFAULT '' COMMENT '方法',
`isdel` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已删除,0正常,1已删除',
PRIMARY KEY (`mid`),
KEY `order` (`ord`),
KEY `module` (`controller`,`action`),
KEY `pid` (`pid`)
) ENGINE=MyISAM AUTO_INCREMENT=180 DEFAULT CHARSET=utf8;
#【插入】菜单
INSERT INTO `admin_menu` VALUES ('3', '0', '1', '0', '0', '', '系统首页', 'home', 'index', '0');
INSERT INTO `admin_menu` VALUES ('4', '3', '1', '0', '0', '', '欢迎页面', 'home', 'welcome', '0');
INSERT INTO `admin_menu` VALUES ('5', '0', '0', '0', '0', 'fa-users', '管理帐号', 'admin', '', '0');
INSERT INTO `admin_menu` VALUES ('6', '5', '0', '0', '0', '', '帐号列表', 'admin', 'index', '0');
INSERT INTO `admin_menu` VALUES ('7', '5', '1', '0', '0', '', '帐号添加', 'admin', 'add', '0');
INSERT INTO `admin_menu` VALUES ('8', '5', '1', '0', '0', '', '帐号保存', 'admin', 'save', '0');
INSERT INTO `admin_menu` VALUES ('167', '5', '1', '0', '0', '', '保存修改', 'Groups', 'save_edit', '0');
INSERT INTO `admin_menu` VALUES ('10', '5', '1', '0', '0', '', '分组添加', 'groups', 'add', '0');
INSERT INTO `admin_menu` VALUES ('11', '5', '1', '0', '0', '', '分组保存', 'groups', 'save', '0');
INSERT INTO `admin_menu` VALUES ('12', '5', '0', '0', '0', '', '权限菜单', 'menus', 'index', '0');
INSERT INTO `admin_menu` VALUES ('13', '5', '1', '0', '0', '', '菜单添加', 'menus', 'add', '0');
INSERT INTO `admin_menu` VALUES ('14', '5', '1', '0', '0', '', '菜单保存', 'menus', 'save', '0');
INSERT INTO `admin_menu` VALUES ('15', '0', '0', '0', '0', 'fa-cogs', '网站设置', 'setting', '', '0');
INSERT INTO `admin_menu` VALUES ('116', '0', '0', '0', '0', '', '文章管理', 'article', '', '0');
INSERT INTO `admin_menu` VALUES ('17', '15', '1', '0', '0', '', '设置保存', 'setting', 'save', '0');
INSERT INTO `admin_menu` VALUES ('62', '15', '0', '1', '0', '', '友情链接', 'setting', 'friend_link', '0');
INSERT INTO `admin_menu` VALUES ('18', '3', '1', '0', '0', '', '首页菜单', 'Home', 'ajax_get_left_menu', '0');
INSERT INTO `admin_menu` VALUES ('84', '15', '1', '0', '0', '', '保存友链', 'setting', 'save_link', '0');
INSERT INTO `admin_menu` VALUES ('120', '15', '1', '0', '0', '', '添加友链', 'setting', 'add_link', '0');
INSERT INTO `admin_menu` VALUES ('121', '15', '1', '0', '0', '', '删除友链', 'setting', 'del_link', '0');
INSERT INTO `admin_menu` VALUES ('182', '15', '1', '0', '0', '', '修改友链', 'setting', 'edit_link', '0');
INSERT INTO `admin_menu` VALUES ('122', '116', '0', '0', '0', '', '文章列表', 'article', 'index', '0');
INSERT INTO `admin_menu` VALUES ('102', '15', '0', '0', '0', '', '基础设置', 'setting', 'index', '0');
INSERT INTO `admin_menu` VALUES ('103', '102', '1', '0', '0', '', '保存基础设置', 'setting', 'save_basesetting', '0');
INSERT INTO `admin_menu` VALUES ('123', '116', '1', '0', '0', '', '添加文章', 'article', 'add', '0');
INSERT INTO `admin_menu` VALUES ('124', '116', '1', '0', '0', '', '保存文章', 'article', 'save', '0');
INSERT INTO `admin_menu` VALUES ('125', '116', '1', '0', '0', '', '删除文章', 'article', 'del', '0');
INSERT INTO `admin_menu` VALUES ('126', '0', '1', '0', '0', '', '文件管理', 'files', '', '0');
INSERT INTO `admin_menu` VALUES ('127', '126', '1', '0', '0', '', '图片上传', 'files', 'uploadimg', '0');
INSERT INTO `admin_menu` VALUES ('128', '116', '0', '0', '0', '', '文章分类', 'article', 'cates', '0');
INSERT INTO `admin_menu` VALUES ('129', '116', '1', '0', '0', '', '保存分类', 'article', 'save_cates', '0');
INSERT INTO `admin_menu` VALUES ('130', '116', '1', '0', '0', '', '添加分类', 'article', 'add_cates', '0');
INSERT INTO `admin_menu` VALUES ('131', '0', '0', '0', '0', '', '商品管理', 'Product', '', '0');
INSERT INTO `admin_menu` VALUES ('132', '131', '0', '0', '0', '', '商品列表', 'Product', 'index', '0');
INSERT INTO `admin_menu` VALUES ('133', '131', '1', '0', '0', '', '商品添加', 'Product', 'add', '0');
INSERT INTO `admin_menu` VALUES ('134', '131', '1', '0', '0', '', '商品保存', 'Product', 'save', '0');
INSERT INTO `admin_menu` VALUES ('135', '131', '0', '0', '0', '', '商品分类', 'Product', 'cates', '0');
INSERT INTO `admin_menu` VALUES ('136', '131', '1', '0', '0', '', '添加分类', 'Product', 'add_cate', '0');
INSERT INTO `admin_menu` VALUES ('137', '131', '1', '0', '0', '', '保存分类', 'Product', 'save_cate', '0');
INSERT INTO `admin_menu` VALUES ('138', '0', '0', '0', '0', '', '订单管理', 'orders', '', '0');
INSERT INTO `admin_menu` VALUES ('139', '138', '0', '0', '0', '', '订单列表', 'orders', 'index', '0');
INSERT INTO `admin_menu` VALUES ('140', '138', '1', '0', '0', '', '订单修改', 'orders', 'add', '0');
INSERT INTO `admin_menu` VALUES ('141', '138', '1', '0', '0', '', '订单保存', 'orders', 'save', '0');
INSERT INTO `admin_menu` VALUES ('142', '0', '0', '0', '0', '', '视频管理', 'video', '', '0');
INSERT INTO `admin_menu` VALUES ('143', '142', '0', '0', '0', '', '视频列表', 'video', 'index', '0');
INSERT INTO `admin_menu` VALUES ('144', '142', '1', '0', '0', '', '视频添加', 'video', 'add', '0');
INSERT INTO `admin_menu` VALUES ('145', '142', '1', '0', '0', '', '上传视频', 'video', 'upload_video', '0');
INSERT INTO `admin_menu` VALUES ('146', '142', '1', '0', '0', '', '保存视频', 'video', 'save', '0');
INSERT INTO `admin_menu` VALUES ('147', '142', '0', '0', '0', '', '视频分类', 'video', 'cates', '0');
INSERT INTO `admin_menu` VALUES ('148', '142', '1', '0', '0', '', '添加分类', 'video', 'add_cate', '0');
INSERT INTO `admin_menu` VALUES ('149', '142', '1', '0', '0', '', '保存分类', 'video', 'save_cate', '0');
INSERT INTO `admin_menu` VALUES ('150', '0', '0', '0', '0', '', '用户管理', 'members', '', '0');
INSERT INTO `admin_menu` VALUES ('151', '150', '0', '0', '0', '', '用户列表', 'members', 'index', '0');
INSERT INTO `admin_menu` VALUES ('152', '5', '1', '0', '0', '', '帐号修改', 'Admin', 'edit', '0');
INSERT INTO `admin_menu` VALUES ('153', '5', '1', '0', '0', '', '帐号删除', 'Admin', 'del', '0');
INSERT INTO `admin_menu` VALUES ('163', '0', '0', '0', '0', '', '后台客服', '', '', '1');
INSERT INTO `admin_menu` VALUES ('155', '5', '1', '0', '0', '', '菜单删除', 'Menus', 'del', '0');
INSERT INTO `admin_menu` VALUES ('160', '0', '1', '0', '0', '', '菜单编辑', 'Menus', 'edit', '0');
INSERT INTO `admin_menu` VALUES ('162', '116', '1', '0', '0', '', '修改状态', 'Article', 'chks', '0');
INSERT INTO `admin_menu` VALUES ('164', '163', '0', '0', '0', '', '客户接待', 'servicer', 'index', '0');
INSERT INTO `admin_menu` VALUES ('165', '131', '1', '0', '0', '', '搜索分类', 'Product', 'search_product_cates', '0');
INSERT INTO `admin_menu` VALUES ('166', '5', '1', '0', '0', '', '修改分组', 'Groups', 'edit', '0');
INSERT INTO `admin_menu` VALUES ('168', '5', '0', '0', '0', '', '分组列表', 'Groups', 'index', '0');
INSERT INTO `admin_menu` VALUES ('169', '0', '1', '0', '0', '', '保存修改的菜单', 'Menus', 'save_edit', '0');
INSERT INTO `admin_menu` VALUES ('170', '0', '0', '0', '0', '', '商户管理', 'Merchant', '', '0');
INSERT INTO `admin_menu` VALUES ('174', '116', '1', '0', '0', '', '文章修改', 'Article', 'edit', '0');
INSERT INTO `admin_menu` VALUES ('175', '116', '1', '0', '0', '', '保存修改', 'Article', 'save_edit', '0');
INSERT INTO `admin_menu` VALUES ('176', '170', '0', '0', '0', '', '商户列表', 'Merchant', 'index', '0');
八、首页模块
1、创建视图模板文件
2、编辑 首页 视图模板 文件
resources/views/admins/home/index.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>欢迎使用XXX后台管理系统</title>
<link rel="stylesheet" href="/static/layui/css/layui.css">
<script src="/static/layui/layui.js"></script>
<style>
.header {
background: #01aaed;
height: 50px;
line-height: 50px;
color: #fff;
padding: 0px 20px;
}
.header .logo-txt {
font-size: 20px;
}
.header .account {
float: right;
}
.header .account a {
margin-left: 5px;
color: #fff;
}
.menus {
width: 200px;
height: calc(100% - 50px);
position: absolute;
background: #333;
}
.main {
position: absolute;
left: 200px;
right: 0px;
height: calc(100% - 50px)
}
.main iframe {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="header">
<span class="logo-txt">XXX后台管理系统</span>
<div class="account">
<span>{{$username}}[{{$group_title}}]</span>
<a href="javascript:;" onclick="logout()">退出</a>
</div>
</div>
{{--左侧菜单--}}
<div class="menus">
<ul class="layui-nav layui-nav-tree" lay-filter="test">
{{-- 遍历主菜单--}}
@foreach($plist as $key=>$p)
<li class="layui-nav-item {{$key==0?'layui-nav-itemed':''}}">
<a href="javascript:">{{$p->title}}</a>
<dl class="layui-nav-child">
{{-- 遍历子菜单--}}
@foreach($p->children as $val)
<dd>
<a href="javascript:" onclick="firememu(this)"
controller="{{$val->controller}}" action="{{$val->action}}">
{{$val->title}}
</a>
</dd>
@endforeach
</dl>
</li>
@endforeach
</ul>
</div>
{{--右侧内容区--}}
<div class="main">
<iframe src="/admins/home/welcome" frameborder="0"></iframe>
</div>
<script>
layui.use(['element', 'layer'], function () {
$ = layui.jquery;
element = layui.element;
layer = layui.layer;
});
// 更新子菜单内容
function firememu(obj) {
const controller = $(obj).attr('controller');
const action = $(obj).attr('action');
const url = '/admins/' + controller + '/' + action;
$('.main iframe').attr('src', url);
}
//退出登录
function logout() {
layer.confirm('您真要退出吗?', {
icon: 3,
btn: ['确定', '取消']
}, function () {
$.get('/admins/account/logout', {}, function (res) {
if (res > 0) {
return layer.alert(res.msg, {icon: 2});
}
layer.msg(res.msg);
setTimeout(function () {
window.location.href = '/admins/account/login';
}, 1000)
}, 'json');
})
}
</script>
</body>
</html>
3、创建 欢迎界面 视图模板文件
4、编辑欢迎界面 视图模板
resources/views/admins/home/welcome.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>欢迎页面</title>
</head>
<body>
<div style="text-align: center;color:gray;font-size: 28px;margin-top: 50px;">
欢迎使用###后台管理系统
</div>
</body>
</html>
5、创建控制器
app/Http/Controllers/admins/Home.php
<?php
namespace App\Http\Controllers\admins;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* 后台主页
* Class Home
* @package App\Http\Controllers\admins
*/
class Home extends Controller {
/**
* 进入主页
* @param Request $req
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function index(Request $req) {
$data['username'] = $req->admin->username;
$data['group_title'] = $req->admin->group_title;
$rights = $req->admin->rights;
//一级菜单
$data['plist'] = DB::table('admin_menu')->where('pid', 0)->where('ishidden', 0)->where('isdel', 0)
->where('status', 0)->whereIn('mid', $rights)->get()->toArray();
foreach ($data['plist'] as $key => $val) {
//查询每个菜单的子菜单
$chds = DB::table('admin_menu')->where('pid', $val->mid)->where('ishidden', 0)->where('isdel', 0)
->where('status', 0)->whereIn('mid', $rights)->get()->toArray();
$data['plist'][$key]->children = $chds;
}
return view('admins/home/index', $data);
}
//主内容区欢迎页面
public function welcome() {
return view('admins/home/welcome');
}
}
6、注册路由
routes/web.php
use App\Http\Controllers\admins\Home;
//后台主页(auth权限验证,rights权利验证-自定义中间件)
Route::namespace('admins')->middleware(['auth', 'rights'])->group(function () {
//首页
Route::get('/admins/home/index', [Home::class, 'index']);
//欢迎模块
Route::get('/admins/home/welcome', [Home::class, 'welcome']);
});
7、查看效果
http://renwushizhan1/admins/home/index