shrooq
2 weeks ago

Too few arguments to function App\Http\Controllers\ProductController::getAddToCart(), 1 passed and exactly 2 expecte

Posted 2 weeks ago by shrooq

tisuchi Sir.

I am getting another problem now. Can you help me?

This is the problem-

Too few arguments to function App\Http\Controllers\ProductController::getAddToCart(), 1 passed and exactly 2 expected.

This is my product controller.

<?php
namespace App\Http\Controllers;

use App\Cart;
use App\Product;
use Illuminate\Http\Request;

use App\Http\Requests;
use Session;

class ProductController extends Controller
{
    public function getProducts()
    {
        $products = Product::all();
        return view('shop', ['products' => $products]);
    }

    public function getAddToCart(Request $request, $id)
    {
        $product = Product::find($id);
        $oldCart = Session::has('cart') ? Session::get('cart') : null;
        $cart = new Cart($oldCart);
        $cart->add($product, $product->id);

        $request->session()->put('cart', $cart);
        dd($request->session()->get('cart'));
        return redirect()->route('shop');
    }
}

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