Laravel Auth::login() doesn’t work after registration

Are you one of those Laravel developers who is having trouble authenticating their freshly created users by calling Auth::login() method? Then continue reading this.

If you are using a non-incrementing primary key for your user table, there is a high chance that you have trouble with authentication sessions in Laravel. This is especially the case when you try to authenticate the User in code right after registration.

To solve this problem you need to add the following property to your User Model. 

it is also mentioned in Eloquent docs that you need to set this property in your models if you are not using an autoincrementing primary key.

Leave a comment

Leave a Reply