laravel 7 登录
1:路由,展示登录表单
Route::group(['prefix'=>'day','namespace'=>'day18'],function (){
// 登录
Route::get('login','ExamController@login');
});
2,HTML:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link href="/static/static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="/static/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="/static/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="/static/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
<title>后台登录 - H-ui.admin v3.1</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
</head>
<body>
<input type="hidden" id="TenantId" name="TenantId" value="" />
<div class="header"></div>
<div class="loginWraper">
<div id="loginform" class="loginBox">
<form class="form form-horizontal" action="{{url('day/dologin')}}" method="post">
@csrf
<div class="row cl">
<label class="form-label col-xs-3"><i class="Hui-iconfont"></i></label>
<div class="formControls col-xs-8">
<input id="" name="username" type="text" placeholder="账户" class="input-text size-L">
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-3"><i class="Hui-iconfont"></i></label>
<div class="formControls col-xs-8">
<input id="" name="password" type="password" placeholder="密码" class="input-text size-L">
</div>
</div> <div class="row cl">
<div class="formControls col-xs-8 col-xs-offset-3">
<input name="" type="submit" class="btn btn-success radius size-L" value=" 登 录 ">
<input name="" type="reset" class="btn btn-default radius size-L" value=" 取 消 ">
</div>
</div>
</form>
{{-- 显示错误信息--}}
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
</div>
</div>
<div class="footer">Copyright 你的公司名称 by H-ui.admin v3.1</div>
<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/static/h-ui/js/H-ui.min.js"></script>
<!--此乃百度统计代码,请自行删除-->
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?080836300300be57b7f34f4b3e97d911";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script> </body>
</html>
3:提交表单路由:
Route::group(['prefix'=>'day','namespace'=>'day18'],function (){
// 处理登录
Route::post('dologin','ExamController@doLogin');
});
4:提交控制器验证
public function doLogin(Request $request){
// 去除token
$params=$request->except('_token');
// 验证非空
$this->validate($request, [
'username' => 'required',
'password' => 'required'
], [
'username.required' => '账号不可以为空',
'password.required' => '密码不可以为空'
], $params);
// 匹配数据库
$res=Admins::login($params);
// 验证账号和密码
if ($res['username']!==$params['username']){
return redirect(url('day/login'))->withErrors(['error'=>'账号错误']);
}elseif ($res['password']!==md5($params['password'])){
return redirect(url('day/login'))->withErrors(['error'=>'密码错误']);
}else{
// 记录session通过put方法
$request->session()->put('username', $res['username']);
//通过全局辅助函数
// session(['username' => $res['username']);
//验证成功跳转首页
return redirect(url('day/new'))->with('success','登录成功');
}
}
5:模型代码:
<?php namespace App\models; use Illuminate\Database\Eloquent\Model; class Admins extends Model
{
//链接表名
protected $table = 'admins';
//验证数据
public static function login($params)
{
//验证账号
return self::where('username',$params['username'])
->first();
}
}
6:效果:

laravel 7 登录的更多相关文章
- laravel 用户名登录
laravel 用户名登录 默认登录设置为用户登录 laravel 5.3+ 修改文件(app\Http\Controllers\Auth\LoginController.php)增加 public ...
- Laravel 项目登录报错:The MAC is invalid.
在 Laravel 项目完成部署到服务器.数据库导入成功后 后台登录报错: 原因是 Laravel 的 APP_KEY 和 encrypt() 函数加密的问题.(encrypt() 是 Laravel ...
- Laravel —— 自定义登录
Laravel 中自带了 Auth 模块 默认用 email 登录,并有固定的表字段 有时需要根据项目需求,修改 Auth 功能 1.生成 Auth 执行 php artisan make:auth ...
- laravel 框架登录 实际操作
//登录中间件 Route::group(['middleware'=>'checkage'],function (){ Route::get('/mou/list','MouControlle ...
- 改造laravel的登录流程,仅使用一个token登录laravel
背景:最近使用lavavel来改造目前的系统,但是之前的老系统还不能立马下线,这时就出现了双系统共存的状态,需要解决的一个问题就是一次登录2个系统. 第一步 修改中间件App\Http\Middlew ...
- laravel记住登录、设置时间
laravel 自动登陆的时间改如何实现? 控制器 public function login(){ $email =Input::get('email');$password = Input::g ...
- laravel 框架登录 参考
一.登录功能1.书写登录路由Route::view('login','login');2.书写登录页面 视图层<form action="{{route('loginDo')}}&q ...
- Laravel 安装登录模块
cmd打开项目目录,执行如下代码即可 php artisan make:auth url访问
- Laravel登录验证碰到的坑 哈希验证匹配问题
用laravel 写登录验证 本来是用Crypt加密 添加用户到数据库的 后来验证密码 解密时一直报错 The payload is invaild 由于本人是laravel框架小白 自己思考许久未 ...
随机推荐
- vc获取进程版本号
#param comment(lib, "version.lib") CString &CMonitorManagerDlg::GetApplicationVersion( ...
- 使用@WebServlet等注解需要i注意的
Servlet 3.0 的部署描述文件 web.xml 的顶层标签 <web-app> 有一个 metadata-complete 属性,该属性指定当前的部署描述文件是否是完全的.如果设置 ...
- Java开发环境及工具安装配置
Java开发环境及工具安装配置 Windows JDK 下载地址 https://www.oracle.com/java/technologies/javase-downloads.html 安装配置 ...
- kebernet--新手填坑
1.安装好kubernet之后,新建rc后,里面的容器一直ImagePullBackOff ,镜像无法拉取: ----需要配置docker镜像为国内镜像,记得在各个Node上都要配置!!! vim / ...
- python 使用pip安装包的总结
multiprocessing.logging模块安装 如果使用在cmd中使用 pip install multiprocessing 会报错, 将命令改为 pip3 install multipro ...
- 【HDU6687】Rikka with Stable Marriage(Trie树 贪心)
题目链接 大意 给定\(A,B\)两个数组,让他们进行匹配. 我们称\(A_i\)与\(B_j\)的匹配是稳定的,当且仅当目前所剩元素不存在\(A_x\)或\(B_y\)使得 \(A_i\oplus ...
- 在VMware上安装Linux虚拟机
1.新建虚拟机 2.选择典型安装 3.点击稍后安装操作系统 4.选择类型和版本 5.选择一个英文路径 6. 7.调整硬件 8. 9. 10.选择第一项 11.选择中文 12.选择最小安装 13. 14 ...
- redis(二)-----redis基本数据类型之字符串
Redis的全称是REmote Dictionary Server,它主要提供了5种数据结构:字符串.哈希.列表.集合.有序集合,同时在字符串的基础之上演变 出了位图(Bitmaps)和HyperLo ...
- [LeetCode]27.移除元素(Java)
原题地址: remove-element 题目描述: 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度. 不要使用额外的数组空间,你必 ...
- MongoDB 带访问控制的副本集部署
当你需要用到一个MongoDB 副本集集群,用于开发测试时, 可以通过下面的步骤简单完成. 版本及环境 MongoDB4.4 Centos6.5 一. 下载安装 MongoDB Server 及 ...