문제

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.

올바른 솔루션이 없습니다

다른 팁

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top