laravel被称为是艺术家 好吧。。。真的的体会到了。。
分析一波用户登陆操作,以前用tp框架登陆都的post提交过来然后对数据库的查询对比然后。。。。
那么就show一波laravel的用户登陆操作吧。。。
掌握技能:用户认证(Auth)相关语法
1.验证信息并登陆:Auth::guard(参数)->attempt(用户名和密码数组,是否保存用户状态:true-是,false-否)
ps:参数是从config配置文件中读取的
2.检查状态:Auth::guard(参数)->check()
3.获得登陆用户:Auth::guard(参数)->user()->数据库字段
4.退出登录:Auth::guard(参数)->logout()
1:视图
![](https://img.haomeiwen.com/i12653063/63ad931e1506a6af.png)
2:路由定义
![](https://img.haomeiwen.com/i12653063/e09aa89c2b12e480.png)
3:模型
![](https://img.haomeiwen.com/i12653063/6983eabe51773abe.png)
4:配置文件
| 修改config/auth.php用户认证配置文件,目的设置【验证用户信息并登陆语法中的参数 Auth::guard(参数)】
![](https://img.haomeiwen.com/i12653063/ba5d6bb023f33a50.png)
5:控制器:
![](https://img.haomeiwen.com/i12653063/f984e44216d14c71.png)
验证:
![](https://img.haomeiwen.com/i12653063/69151fb2892ba23c.png)
6:错误闪存提示信息:
![](https://img.haomeiwen.com/i12653063/45d17c48b91851a6.png)
<script type="text/javascript">
@if (count($errors) > 0)
var errors = '';
@foreach ($errors->all() as $error)
errors += "{{ $error }} \n";
@endforeach
alert(errors);
@endif
</script>
马上要找工作了 据说好工作也要有好的运气 老天保佑我一下啊!!!
网友评论