Laravel 5.2服务----用户验证Auth相关问题

关于laravel的auth()用户认证这一块,面前我也是,有用到,有碰到什么问题我就记录下来。

手动认证用户

<?php

namespace App\Http\Controllers;

use Auth;
use Illuminate\Routing\Controller;

class AuthController extends Controller{
    /**
     * 处理登录认证
     *
     * @return Response
     */
    public function authenticate()
    {
        if (Auth::attempt(['email' => $email, 'password' => $password])) {
            // 认证通过...
            return redirect()->intended('dashboard');
        }
    }
}
一次性认证用户

once 方法只在单个请求中将用户登录到应用,而不存储任何 Session 和 Cookie,这在构建无状态的 API 时很有用。once方法和attempt方法用法差不多:

if (Auth::once($credentials)) {
    //
}

 

posted @ 2017-03-09 17:20  洪先森  阅读(162)  评论(0编辑  收藏  举报