app/Http/Controllers/AdminController.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,$name,$nameShow)
    {
        if($name == "products"){
            $id_product = $request->post('id');
            $name_product = $request->post('name');
            $manu_id = $request->post('manu');
            $type_id = $request->post('type');
            $price = $request->post('price');
            $saleprice = $request->post('saleprice');
            $desc = $request->post('desc');
            $feature = $request->post('feature');
            $status = $request->post('status');
            $chip = $request->post('Chip');
            $ram = $request->post('Ram');
            $Capacity = $request->post('Capacity');
            $quantity = $request->post('quantity');
            $HDH = $request->post('HDH');
            $origin = $request->post('origin');
            $request->hasFile('image');
            $img = $request->image;
            if($img != null){
                $Location = "..\public\assets\pages\img\products";
                $imageName = $img->getClientOriginalName();
                if(!@is_array(getimagesize($Location.$imageName))){
                    $img->move($Location, $img->getClientOriginalName());
                    DB::update('update product set name = ?, manu_id = ?, type_id = ?, price = ?, 
                    sale_price = ?, description = ?, feature = ?, quantity = ?, status = ?, Ram = ?
                    , Capacity= ?, chip = ?, origin = ?, image=? where id = ?',[$name_product,$manu_id,
                    $type_id,$price,$saleprice,$desc,$feature,$quantity,$status,$ram,$Capacity,
                    $chip,$origin, $imageName,$id_product]);
                } else {
                    $message = "Lỗi chọn không phải ảnh";
                    echo "<script type='text/javascript'>alert('$message');</script>";
                }
            }else{
                DB::update('update product set name = ?, manu_id = ?, type_id = ?, price = ?, 
                sale_price = ?, description = ?, feature = ?, quantity = ?, status = ?, Ram = ?
                , Capacity= ?, chip = ?, origin = ? where id = ?',[$name_product,$manu_id,
                $type_id,$price,$saleprice,$desc,$feature,$quantity,$status,$ram,$Capacity,
                $chip,$origin,$id_product] );
             }            
        }elseif($name == "protypes"){
            $id_protype = $request->post('id');
            $name_protype = $request->post('name');
            DB::update('update protypes set type_name = ? where id = ?', [$name_protype,$id_protype]);
        }
        else{
            $id_manu = $request->post('id');
            $name_manu = $request->post('name');
            $request->hasFile('image');
            $img = $request->image;
            if($img != null){
                $Location = "..\public\assets\pages\img\brands";
                $imageName = $img->getClientOriginalName();
                if(!@is_array(getimagesize($Location.$imageName))){
                    $img->move($Location, $img->getClientOriginalName());
                    DB::update('update manufactures set manu_name = ?, image = ? where id = ?', [$name_manu,$imageName,$id_manu]);
                } else {
                    $message = "Lỗi chọn không phải ảnh";
                    echo "<script type='text/javascript'>alert('$message');</script>";
                }
            }else {
                DB::update('update manufactures set manu_name = ? where id = ?', [$name_manu,$id_manu]);
            }
        }
         $manufactures = Manufactures::all();
         $products = DB::table('product')
            ->join('manufactures', 'product.manu_id', '=', 'manufactures.id')
            ->join('protypes', 'product.type_id', '=', 'protypes.id')
            ->select('product.*', 'manufactures.manu_name', 'protypes.type_name')
            ->get();
        $protypes = Protype::all();
        return view($name)->with('getProducts', $products)
            ->with('getProtypes', $protypes)
            ->with('getManufactures', $manufactures);
    }
public function update ( Request $ request , $ name , $ nameShow ) { if ( $ name == " products " ) { $ id_product = $ request -> post ( 'id' ) ; $ name_product = $ request -> post ( 'name' ) ; $ manu_id = $ request -> post ( 'manu' ) ; $ type_id = $ request -> post ( 'type' ) ; $ price = $ request -> post ( 'price' ) ; $ saleprice = $ request -> post ( 'saleprice' ) ; $ desc = $ request -> post ( 'desc' ) ; $ feature = $ request -> post ( 'feature' ) ; $ status = $ request -> post ( 'status' ) ; $ chip = $ request -> post ( 'Chip' ) ; $ ram = $ request -> post ( 'Ram' ) ; $ Capacity = $ request -> post ( 'Capacity' ) ; $ quantity = $ request -> post ( 'quantity' ) ; $ HDH = $ request -> post ( 'HDH' ) ; $ origin = $ request -> post ( 'origin' ) ; $ request -> hasFile ( 'image' ) ; $ img = $ request -> image ; if ( $ img != null ) { $ Location = " ..\public\assets\pages\img\products " ; $ imageName = $ img -> getClientOriginalName ( ) ; if ( ! @ is_array ( getimagesize ( $ Location . $ imageName ) ) ) { $ img -> move ( $ Location , $ img -> getClientOriginalName ( ) ) ; DB :: update ( 'update product set name = ?, manu_id = ?, type_id = ?, price = ?, 
                    sale_price = ?, description = ?, feature = ?, quantity = ?, status = ?, Ram = ?
                    , Capacity= ?, chip = ?, origin = ?, image=? where id = ?' , [ $ name_product , $ manu_id , $ type_id , $ price , $ saleprice , $ desc , $ feature , $ quantity , $ status , $ ram , $ Capacity , $ chip , $ origin , $ imageName , $ id_product ] ) ; } else { $ message = " Lỗi chọn không phải ảnh"; echo " <script type='text/javascript'>alert(' $ message ');</script> " ; } } else { DB :: update ( 'update product set name = ?, manu_id = ?, type_id = ?, price = ?, 
                sale_price = ?, description = ?, feature = ?, quantity = ?, status = ?, Ram = ?
                , Capacity= ?, chip = ?, origin = ? where id = ?' , [ $ name_product , $ manu_id , $ type_id , $ price , $ saleprice , $ desc , $ feature , $ quantity , $ status , $ ram , $ Capacity , $ chip , $ origin , $ id_product ] ) ; } } elseif ( $ name == " protypes " ) { $ id_protype = $ request -> post ( 'id' ) ; $ name_protype = $ request -> post ( 'name' ) ; DB :: update ( 'update protypes set type_name = ? where id = ?' , [ $ name_protype , $ id_protype ] ) ; } else { $ id_manu = $ request -> post ( 'id' ) ; $ name_manu = $ request -> post ( 'name' ) ; $ request -> hasFile ( 'image' ) ; $ img = $ request -> image ; if ( $ img != null ) { $ Location = " ..\public\assets\pages\img\brands " ; $ imageName = $ img -> getClientOriginalName ( ) ; if ( ! @ is_array ( getimagesize ( $ Location . $ imageName ) ) ) { $ img -> move ( $ Location , $ img -> getClientOriginalName ( ) ) ; DB :: update ( 'update manufactures set manu_name = ?, image = ? where id = ?' , [ $ name_manu , $ imageName , $ id_manu ] ) ; } else { $ message = " Lỗi chọn không phải ảnh"; echo " <script type='text/javascript'>alert(' $ message ');</script> " ; } } else { DB :: update ( 'update manufactures set manu_name = ? where id = ?' , [ $ name_manu , $ id_manu ] ) ; } } $ manufactures = Manufactures :: all ( ) ; $ products = DB :: table ( 'product' ) -> join ( 'manufactures' , 'product.manu_id' , '=' , 'manufactures.id' ) -> join ( 'protypes' , 'product.type_id' , '=' , 'protypes.id' ) -> select ( 'product.*' , 'manufactures.manu_name' , 'protypes.type_name' ) -> get ( ) ; $ protypes = Protype :: all ( ) ; return view ( $ name ) -> with ( 'getProducts' , $ products ) -> with ( 'getProtypes' , $ protypes ) -> with ( 'getManufactures' , $ manufactures ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//