使用AuthenticatesUsers特性在laravel 5.2中登录失败

时间:2016-11-01 09:27:18

标签: php authentication laravel-5.2

我正在使用AuthenticatesUsers特性来处理我网站中的登录。 当我在网站上注册新用户时,它可以成功登录和注销,但是当我通过登录表单登录时,即使我提供了正确的数据,它也会每次都失败。我不明白为什么会这样。我做错了什么?这是我的auth控制器。

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{       

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    protected $redirectTo = '/home';
    protected $guard = 'user';

    public function __construct()
    {

        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }


    protected function validator(array $data)
    {
        return Validator::make($data, [
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
        ]);
    }


    protected function create(array $data)
    {
        return User::create([
            'first_name' => $data['firstName'],
            'last_name' => $data['lastName'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

Route.php

<?php


Route::group(['middleware' => ['web']], function () {
    // Your route here

//    // Authentication routes...
    Route::get('customer/login', 'Customer\Auth\AuthController@getLogin');
    Route::post('customer/login', 'Customer\Auth\AuthController@postLogin');
    Route::get('customer/logout', 'Customer\Auth\AuthController@getLogout');
//
//    // Registration routes...
    Route::get('customer/register', 'Customer\Auth\AuthController@getRegister');
    Route::post('customer/register', 'Customer\Auth\AuthController@postRegister');

    Route::auth();

    Route::get('/home', function (){
        return view('welcome');
    });
});       

Route::get('/home', 'HomeController@index');

0 个答案:

没有答案