0

我正在尝试 Laravel 的 Auth 类,但该方法总是返回 false。这是我的代码:

控制器 :

public function postLogin()
    {
        // Declare the rules for the form validation.
        //
        $rules = array(
            'email'    => 'Required|Email',
            'password' => 'Required'
        );

        // Get all the inputs.
        //
        $email = Input::get('email');
        $password = Input::get('password');
        // Validate the inputs.
        //
        $validator = Validator::make(Input::all(), $rules);

        // Check if the form validates with success.
        //
        if ($validator->passes())
        {
                   //echo $password; displays test
            // Try to log the user in.
            //
            if (Auth::attempt(array('email' => $email, 'password' => $password)))
            {


                // Redirect to the users page.
                //
                return Redirect::to('account')->with('success', 'You have logged in successfully');
            }
            else
            {
                // Redirect to the login page.
                //
                return Redirect::to('account/login')->with('error', 'Email/password invalid.');
            }
        }

        // Something went wrong.
        //
        return Redirect::to('account/login')->withErrors($validator->getMessageBag());
    }

播种机.php

公共函数 run() { DB::table('users')->delete();

$users = array(
    array(
        'email'      => 'test@test.com',
        'password'   => Hash::make('test'),
    'first_name' => 'John',
    'last_name'  => 'Doe',
        'created_at' => new DateTime,
        'updated_at' => new DateTime,
    )
);

DB::table('users')->insert( $users );

}

4

2 回答 2

1

这将是因为框架错误。所以尝试更新它。

composer update

或者

php composer.phar update
于 2013-09-19T11:27:15.380 回答
1

在您的 config/auth.php 文件中,尝试从 'driver' => 'eloquent' 更改为 'driver' => 'database'。

于 2013-09-19T14:25:22.200 回答