使用的技术:Php Laravel 6
命名空间App \ Http \ Controllers;
使用App \ Http \ Controllers \ Controller;
使用Illuminate \ Support \ Facades \ DB;
使用Illuminate \ Http \ Request;
使用App \ Product;
使用会话;
使用Auth;
CartController类扩展Controller
{
公共功能addtocart(Request $ request){
$ id = $ request-> proid;
$ quantity = $ request-> quantity;
$ product = Product :: find($ id);
$ cart = $ request-> session()-> get('cart');
if(isset($ cart [$ product ['Product_ID']])):
$ cart [$ product ['Product_ID']] ['qty'] + = $ quantity;
其他:
$ cart [$ product ['Product_ID']] = $ product;
$ cart [$ product ['Product_ID']] ['qty'] = $ quantity;
万一;
会话:: push('cart',$ cart);
返回视图('frontend.cart.addedtocart',compact('product'));
}
}
你能不能请任何人帮助我?