4 years ago

Laravel relationship gets different eloquent model with and without first() function

Posted 4 years ago by eldringoki

I have these 2 models user and cart implemented with 1 to 1 relationship.

$user = \Auth::user();
$cart = $user->cart()->first(); // returns a wrong record of cart 
$cart2 = $user->cart(); // returns the right one


this is the screenshot of the dumped objects http://imgur.com/mwu6kuK

Please sign in or create an account to participate in this conversation.