简体   繁体   中英

Laravel 4 Auth::attempt() issue

I'm trying the Laravel's Auth class but the method returns false always. Here's my code:

Controller :

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());
    }

Seeder.php

public function 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 );

}

It will be because of framework bug. So try to update it.

composer update

Or

php composer.phar update

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM