Could just login the user using:
Auth::loginUsingId($response->_id);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello!
I have two projects (Api, and an App)
From my app when the user try loggin, my method getPost call by cURL to Api, and this return a response json with a Token and object User if all was right.
object(stdClass)#291 (3) { ["status"]=> string(2) "ok" ["user"]=> object(stdClass)#292 (13) { ["_id"]=> string(1) "1" ["name"]=> string(6) "Carlos" ["password"]=> string(60) "$2y$10$DKcfWRA5zZ1IB8wwt.7LGe055emuoml2GabwXOKSHcxaafZb.6oIi" ["rol"]=> string(5) "super" } ["token"]=> string(333) "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiaXNzIjoiaHR0cDpcL1wvYXBpLmxvY2FscGxheW1vLmVzXC92MVwvYXV0aGVudGljYXRlIiwiaWF0IjoiMTQ0MzczNzAxMSIsImV4cCI6IjE0NDM3NDA2MTEiLCJuYmYiOiIxNDQzNzM3MDExIiwianRpIjoiMmEzNmFkM2E1YmZmYzFiY2RkZTQ2NmQyMmZiMWIzYjciLCJyb2wiOiJzdXBlciIsIm5hbWUiOm51bGx9.tfsq6LXHA4ekPDQmOS5Ym0CU8m5e2TFdE7reMNjfGN8" }
But I dont know how create a session when the response was good. I try this:
Auth::login($response->user);
But not work, I recieve this error
Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of stdClass given
Someone can help me?
Thanks!
@bobbybouwmann I thought about what you said and my solution is create a function in User model that recieve an array and return a user objetc
public function getUser($user)
{
$userContract = new User();
$userContract->_id = $user->_id;
$userContract->name = $user->name;
$userContract->rol = $user->rol;
$userContract->email = $user->email;
return $userContract;
}
What do you think?
thanks!
Please or to participate in this conversation.