'Unresolvable dependency resolving [Parameter #0 [ <required> $prevCart ]] in class App\Models\Cart
been having issues with my cart model. seem not to find where the error is coming from. it keeps returning 'Unresolvable dependency resolving [Parameter #0 [ $prevCart ]] in class App\Models\Cart' please I need help.my Cart Model
`<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class Cart extends Model
{
use HasFactory;
public $items;
public $totalQuantity;
public $totalPrice;
public function __construct($prevCart){
if($prevCart !=null){
$this->items = $prevCart->items;
$this->totalQuantity = $prevCart->totalQuantity;
$this->totalPrice = $prevCart->totalPrice;
}else{
$this->items = [];
$this->totalQuantity = 0;
$this->totalPrice = 0;
}
}
public function addItem($unique_id, $product){
$price = (int) str_replace('$', '', $product->price);
//if product already exists
if(array_key_exists($unique_id, $this->items)){
$productToAdd = $this->items[$unique_id];
$productToAdd['quantity']++;
}else{
$productToAdd = ['quantity'=>0, 'price'=> $price, 'data'=>$product];
}
$productToAdd = $this->items[$unique_id];
$this->totalQuantity++;
$this->totalPrice = $this->totalPrice + $price;
}
}
`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
