Question

I use Laravel 4 and Auth::attempt() like this code:

$cred = array(
                'email'     => Input::get('email'),
                'password'  => Input::get('password'),
                'active'    => 1, //user must be activated before
            );
            if (Auth::attempt($cred, false)) 
            {
                // the auth.attempt event will be fired
                return Redirect::to(URL::action('Admin@index'));
            }

and it works fine but when I call user email with command

Auth::user()->email;

It always return the first user in the Users table even I have logged in with other user's cred.

for example, If I have multiple users in DB, then even I send cred of user2 or user3 it always return user1.

No correct solution

OTHER TIPS

I can think of two issues that can cause this:

Session

Auth::user();

accesses the user session in order to get the token from which it can identify the user in the model, so flush the session and try to login with the other users, using:

Session::flush();

Database

I would want to go to the database to make sure everything is under the logic expectations, take a look at a couple of rows of the user table, especially the ID column and the Email.

i don't think that this should be considered as a direct answer, rather than where to look and what might cause the problem, hope it works out with you!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top