In your question, you say that you’re calling a method getTotal()
, but there’s no such method in the code sample you’re linking to. I’m going to assume that you meant getPrice()
.
If a user has many carts, you can’t get a single one with just $user->cart
, since that will contain the Collection
of all of the user’s carts.
If you want to show the total for each cart a user has, you could rename the method to carts()
and do e.g.
@foreach ($user->carts as $cart)
{{ $cart->getPrice() }}
@endforeach
Otherwise, you’ll get the error you mention in your topic.
1
solved Laravel Method Does not Exist [closed]