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

Posted 3 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

dd($cart,$cart2);

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

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

Reply to

Use Markdown with GitHub-flavored code blocks.