Laravel Auth:attempt() will not persist login
I had this problem. Changing primary key for user model helped for me.
Try to add something like
protected $primaryKey = 'user_id';
in class User{} (app/models/User.php)
(Field user_id
is auto increment key in my Schema for 'users' table)
See also this ticket: https://github.com/laravel/framework/issues/161
I had the same issue in laravel 5.7. Whoever facing similar issues if session not persisting after authentication , can follow the solution like below..
Open file App\Http\kernel.php
Move \Illuminate\Session\Middleware\StartSession::class,
from protected $middlewareGroups
to protected $middleware
. That's it.
I had this problem today morning, and I realized that when you output data before calling
Auth::attempt($credentials);
Then you can BE SURE THAT YOUR SESSION WILL NOT BE SET.So for example if you do something like
echo "This is the user " . $user;
just above the line that says
Auth::attempt($credentials);
Then rest assured that you will spend the whole morning trying to find why laravel is not persisting the authenticated user and calling
Auth::user()
will give you a null, and also calling
Auth::check()
will always give you false.
This was my problem and that is how I fixed it, by removing the echo statement.