<?php

namespace App\Http\Controllers;

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

class ShopController extends Controller
{
    //
    public function add_to_cart(){
        $product = Product::find(request()->product_id);
        $item = Cart::add([
            'id' =>  $product->id,
            'name' => $product->name,
            'qty' => request()->qte,
            'price' =>  $product->prix
        ]);
        Cart::associate($item->rowId,'App\Product');
        return redirect()->route('cart.index');
    }
    public function cart(){
        //Cart::destroy();
        return view('admin.products.cart');
    }
    public function cart_delete($id){
        Cart::remove($id);
        return redirect()->back();
    }
    public function cart_dec($id,$qte){
        Cart::update($id,$qte - 1);
        return redirect()->back();
    }
    public function cart_inc($id,$qte){
        Cart::update($id,$qte + 1);
        return redirect()->back();
    }
}
