mercredi 27 décembre 2017

Method error 500 after move to Repository

i would like to get some help why ? i cant figure out why my ajax post request doesnt work when i move it into Repository to clean my Controller code

Laravel 5.5 Error code : 500

ajax call have _token header so problem should be not in ajax call

Working method in Controller :

public function postAjaxAddToCart(Request $request, $id, $size)
{
    $product = Product::findOrFail($id);
    $oldCart = Session::has("cart") ? Session::get("cart") : null;
    $cart    = new Cart($oldCart);
    $cart->add($product, $product->id, $size);

    $request->session()->put("cart", $cart);
}

doesnt works after move to Repository class:

 public function postAjaxAddToCart(Request $request, $id, $size)
{
    $this->productRepository->addToCardAjax($request, $id, $size);

}

repository method looks like:

public function addToCardAjax($request, $id, $size) {

    $item = $this->model::findOrFail($id);
    $oldCart = Session::has("cart") ? Session::get("cart") : null;
    $cart    = new Cart($oldCart);
    $cart->add($item, $item->id, $size);

    $request->session()->put("cart", $cart);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire