laravel中的登录页面逻辑

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;

class LoginController extends Controller
{
    //登录页面:
    public function index()
    {
        return view('login.index');
    }

    //登录行为:
    public function login()
    {
        //验证:
        $this->validate(\request(), [
            'email' => 'required|email',
            'password' => 'required|min:5|max:10',
            'is_remember' => 'integer'
        ]);
        //逻辑:
        $user = \request(['email', 'password']);
        $is_remember = boolval(\request('is_remember'));
        if (Auth::attempt($user, $is_remember)) {
            return redirect('/posts');
        }
        //渲染:
        return Redirect::back()->withErrors('邮箱密码不匹配');
    }

    //退出行为:
    public function logout()
    {
        Auth::logout();
        return \redirect('login');
    }
}

  

posted @ 2018-03-26 07:24  生如逆旅,一苇以航  阅读(322)  评论(0编辑  收藏  举报