app/Http/Controllers/admin/GoodsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $data = $request->except('_token');
        $filedir = self::uploads($request);
        $goods = [
            'gcid'=>$data['gcid'],
            'name'=>$data['name'],
            'pic'=>$filedir,
            'discount'=>$data['discount'],
            'price'=>$data['price'],
            'intro'=>$data['intro'],
        ];
        $gid = DB::table('jc_goods')->insertGetId($goods);
        $gd =[
            'gid'=>$gid,
            'type'=>$data['type'],
            'color'=>$data['color'],
            'describe'=>$data['describe'],
        ]; 
        $res = DB::table('jc_goods_details')->insert($gd);
        if($res&&$gid){
            return redirect('/admin/goods')->with('success','商品添加完成');
        }else{
             return back()->with('error','商品添加失败');
        }
    }
public function store ( Request $ request ) { $ data = $ request -> except ( '_token' ) ; $ filedir = self :: uploads ( $ request ) ; $ goods = [ 'gcid' => $ data [ 'gcid' ] , 'name' => $ data [ 'name' ] , 'pic' => $ filedir , 'discount' => $ data [ 'discount' ] , 'price' => $ data [ 'price' ] , 'intro' => $ data [ 'intro' ] , ] ; $ gid = DB :: table ( 'jc_goods' ) -> insertGetId ( $ goods ) ; $ gd = [ 'gid' => $ gid , 'type' => $ data [ 'type' ] , 'color' => $ data [ 'color' ] , 'describe' => $ data [ 'describe' ] , ] ; $ res = DB :: table ( 'jc_goods_details' ) -> insert ( $ gd ) ; if ( $ res && $ gid ) { return redirect ( '/admin/goods' ) -> with ( 'success' , '商品添加完成'); } else { return back ( ) -> with ( 'error' , '商品添加失败'); } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//添加 // dump($data); // dd($filedir); //将数据分开存入两张表中 // dump($gid); // dump($res);