Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lukegalea16's avatar

Auth::login a User instance

When using Auth::login($user) is it possible to login (and so a session is created) a $user instance created on the fly. For example:

$user = new User();
$user->id = 15;
$user->name = "User Name";
$user->email = "test";
$user->password = "test";
Auth::login($user);

The reason for this is that I am storing my users in another Database 'app' in another Laravel project. Thus when a user logs in from this dashboard, I'd like the credentials to be verified in project 'app' through an API call and then return back information such as user_id and create a session in this Laravel project.

0 likes
3 replies
lukegalea16's avatar

Hi @rkdev , I found out that a session is not persisted if the user does not exist in the DB. If I create a user with that id in the DB then it works. So basically I want to create a custom Auth Guard or disable the DB Provider for the Laravel Auth somehow...

lukegalea16's avatar

If someone implemented this (custom user provider or disabling it for Auth) and can guide me - I'd really appreciate it.

Please or to participate in this conversation.