mardi 14 avril 2020

How can i change this session so it adds item to basket Laravel 5.5

Please can you help update this code so that the session allows adding items to a basket, Laravel 5.5, thanks.

i am following a larvel tutotial which is older and am having difficultiy with it, thanks

<?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 getIndex()
    {


         $products = Product::all();        
         return view('shop.index', ['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.index');

    }


}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire