app/Http/Controllers/admin/GoodsController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $data = $request->except('_token');
        if($request -> hasFile('pic')){
            $filedir = self::uploads($request);
        }else{
            $goods = Goods::find($id);
            $filedir = $goods->pic;
        }
        $goods = [
            'gcid'=>$data['gcid'],
            'name'=>$data['name'],
            'pic'=>$filedir,
            'discount'=>$data['discount'],
            'price'=>$data['price'],
            'intro'=>$data['intro'],
        ];
        $res1 = DB::table('jc_goods')->where('id',$id)->update($goods);
        $gd =[
            'type'=>$data['type'],
            'color'=>$data['color'],
            'describe'=>$data['describe'],
        ]; 
        $res2 = DB::table('jc_goods_details')->where('gid',$id)->update($gd);
        if($res1||$res2){
            return redirect('/admin/goods')->with('success','商品修改完成');
        }else{
             return back()->with('error','商品修改失败');
        }
    }
public function update ( Request $ request , $ id ) { $ data = $ request -> except ( '_token' ) ; if ( $ request -> hasFile ( 'pic' ) ) { $ filedir = self :: uploads ( $ request ) ; } else { $ goods = Goods :: find ( $ id ) ; $ filedir = $ goods -> pic ; } $ goods = [ 'gcid' => $ data [ 'gcid' ] , 'name' => $ data [ 'name' ] , 'pic' => $ filedir , 'discount' => $ data [ 'discount' ] , 'price' => $ data [ 'price' ] , 'intro' => $ data [ 'intro' ] , ] ; $ res1 = DB :: table ( 'jc_goods' ) -> where ( 'id' , $ id ) -> update ( $ goods ) ; $ gd = [ 'type' => $ data [ 'type' ] , 'color' => $ data [ 'color' ] , 'describe' => $ data [ 'describe' ] , ] ; $ res2 = DB :: table ( 'jc_goods_details' ) -> where ( 'gid' , $ id ) -> update ( $ gd ) ; if ( $ res1 || $ res2 ) { return redirect ( '/admin/goods' ) -> with ( 'success' , '商品修改完成'); } else { return back ( ) -> with ( 'error' , '商品修改失败'); } }
Update the specified resource in storage.
Update the specified resource in storage .
//添加 // dump($data); //将数据分开存入两张表中 // dump($gid); // dump($res);