laravel 5中的登录问题

时间:2015-09-02 07:03:47

标签: php login laravel-5

我正在尝试在laravel 5.中创建登录。但每次我收到此错误These credentials do not match our records。我的代码是这样的:

路线页:

Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

控制器:

<?php

namespace App\Http\Controllers\Auth;

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

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

     /**
     * Show the application login form.
     *
     * @return Response
     */
    public function getLogin()
    {
        return view('auth.login');
    }

    /**
     * Handle a login request to the application.
     *
     * @param  LoginRequest  $request
     * @return Response
     */
    public function postLogin(LoginRequest $request)
    {

      if (Auth::attempt(['email' => $email, 'password' => $password])) 
        {
            return redirect('/dash-board');
        }

        return redirect('/login')->withErrors([
            'email' => 'The credentials you entered did not match our records. Try again?',
        ]);
    }

}

我的观点表单行动是这样的:

<form accept-charset="UTF-8" action="http://bucketspms-plumnetworks.c9.io/auth/login" method="POST">

我是Laravel的新手,所以很困惑为什么它不允许我登录。

1 个答案:

答案 0 :(得分:0)

您使用的是 $ email和$ password ,但这些变量未设置,您应使用 $ request-&gt;输入('email')和$ request-&gt;输入此功能中的('密码')

public function postLogin(LoginRequest $request)
{

  if (Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')])) 
    {
        return redirect('/dash-board');
    }

    return redirect('/login')->withErrors([
        'email' => 'The credentials you entered did not match our records. Try again?',
    ]);
}