나는 Laravel 8로 온라인 상점을 만들려고하는데 cart.blade.php
이것을 코딩했습니다.
<div class="text-right mt-4">
<label class="text-muted font-weight-normal m-0">Final Price</label>
@php
$totalPrice = Cart::all()->sum(function($cart) {
return $cart['product']->price * $cart['quantity'];
});
@endphp
<div class="text-large"><strong>{{ $totalPrice }} is price</strong></div>
</div>
그리고 방법 all()
은 다음과 같습니다.
public function all()
{
$cart = $this->cart;
$cart = $cart->map(function($item) {
return $this->withRelationshipIfExist($item);
});
return $cart;
}
그렇다면이 문제를 해결하는 방법은 무엇입니까? 여러분의 아이디어 나 제안에 감사드립니다.
미리 감사드립니다.
오류는 $ cart가 개체가 아니라는 것을 나타냅니다. 이것은 올바르게 설정되지 않았을 때 발생합니다.
all () 함수가 카트 모델에 있으면 실제로 $ this-> cart를 원하지 않습니다. 당신은 단순히 $ cart = $ this를 원할 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다