app/Http/Controllers/home/ShopCarController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index(Request $request)
    { 
        $good_car = session('goods');
        $uid = session('homeuser')['id'];
        $zsum = 0;
        $shops = session('goods')?session('goods'):null;
        if(session('homeflag')){
            if($shops){
                $uid = session('homeuser')['id'];
                $good_car = $request->session()->pull('goods');
                foreach ($good_car as $k => $v) {
                    $shops = new Shopcars;
                    $shops -> uid = $uid;
                    $shops -> gid = $v['id'];
                    $shops -> gname = $v['info']->name;
                    $shops -> gnum = $v['num'];
                    $shops -> gprice = $v['info']->discount;
                    $shops -> gcolor = $v['color'];
                    $shops -> gpic = $v['info']->pic;
                    $shops -> gtype = $v['info']->detailsgoods->type;
                    $shops -> save();   
                }
            }
            $shops = ShopCars::where('uid',$uid)->get();
        }
        return view('home.goods.shopcar')->with(['shops'=>$shops,'zsum'=>$zsum]);
    }
public function index ( Request $ request ) { $ good_car = session ( 'goods' ) ; $ uid = session ( 'homeuser' ) [ 'id' ] ; $ zsum = 0 ; $ shops = session ( 'goods' ) ? session ( 'goods' ) : null ; if ( session ( 'homeflag' ) ) { if ( $ shops ) { $ uid = session ( 'homeuser' ) [ 'id' ] ; $ good_car = $ request -> session ( ) -> pull ( 'goods' ) ; foreach ( $ good_car as $ k => $ v ) { $ shops = new Shopcars ; $ shops -> uid = $ uid ; $ shops -> gid = $ v [ 'id' ] ; $ shops -> gname = $ v [ 'info' ] -> name ; $ shops -> gnum = $ v [ 'num' ] ; $ shops -> gprice = $ v [ 'info' ] -> discount ; $ shops -> gcolor = $ v [ 'color' ] ; $ shops -> gpic = $ v [ 'info' ] -> pic ; $ shops -> gtype = $ v [ 'info' ] -> detailsgoods -> type ; $ shops -> save ( ) ; } } $ shops = ShopCars :: where ( 'uid' , $ uid ) -> get ( ) ; } return view ( 'home.goods.shopcar' ) -> with ( [ 'shops' => $ shops , 'zsum' => $ zsum ] ) ; }
Display a listing of the resource.
Display a listing of the resource .
// dump($shops); //将商品的个数存入session