简体   繁体   中英

I am using this Laravel Cart package olimortimer/laravelshoppingcart, where it's storing items in same cart for every users.using REST API

HERE i am trying to make REST API's using the mentioned package but it doesn't seems working with API Can you point out if i am making mistake.

class CartController extends Controller
{
public function ShowCart(){
    
    $content = Cart::content();
    return response()->json(['success'=>'true','item-list'=>$content]);

}

public function AddItemToCart(Request $request,$id){
              
        $item = FoodItem::where('id',$id)->first();
        Cart::add($item->id,$item->item_name,1,$item->price, ['image' => $request->image ,   
    'extras' =>$request->extras,'attribute'=>$request->attributes,]);
    return response()->json(['success'=>'true']);

}

public function AddQuantity($rowId){
    $row = Cart::get($rowId);
    Cart::update($rowId,  $row->qty +1);
    return response()->json(['success'=>'true']);
}

public function SubstractQuantity($rowId){
    $row = Cart::get($rowId);
    Cart::update($rowId,$row->qty - 1);
    return response()->json(['success'=>'true']);
}

public function DiscardCart(){
  Cart::destroy();
  return response()->json(['success'=>'true']);
}

}

Your package is working with session and not a database. As far as I understand what you are trying to do, I would not use this package to make an API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM