app/Http/Controllers/ProductController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Product  $product
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $products)
    {
        $product_code = $request-> product_code;
        $products = Product::find($products);
        if ($request->hasFile('product_image')){
            if ($products->product_image !=''){
                $proimage_path = public_path().'/product/images/'.$products->product_image.'jpg';
                unlink($proimage_path);
            }
            $file = $request->file('product_image');
            $file->move(public_path(). '/product/images', $file->getClientOriginalName());
            $product_image = $file->getClientOriginalName();  
            $products->product_image = $product_image;      
        }
            if ($request->product_code != '' && $request->product_code != $products->product_code){
                 if ($products->barcode !=''){
                     $barcode_path = public_path().'/product/barcodes/'.$product_code.'jpg';
                     unlink($barcode_path);
                 }
                $product_code = $request->product_code;
                $redColor = '255,0,0';
                $generator = new Picqer\Barcode\BarcodeGeneratorJPG();
                file_put_contents('product/barcodes/'.$product_code .'.jpg',
                $generator->getBarcode($product_code,
                $generator::TYPE_CODE_128, 3, 50));
                $products->barcode = $product_code . '.jpg';
            }
      $products->product_name = $request->product_name;
      $products->product_code = $product_code;
      $products->quantity = $request->quantity; 
      $products->price = $request->price;
      $products->brand = $request->brand;
      $products->alert_stock = $request->alert_stock;
      $products->description = $request->description;
      $products->save();
      return redirect()->back()->with('success', 'product successfully created');    
        return redirect()->back()->with('success','info successfully updated');
    }
public function update ( Request $ request , $ products ) { $ product_code = $ request -> product_code ; $ products = Product :: find ( $ products ) ; if ( $ request -> hasFile ( 'product_image' ) ) { if ( $ products -> product_image != '' ) { $ proimage_path = public_path ( ) . '/product/images/' . $ products -> product_image . 'jpg' ; unlink ( $ proimage_path ) ; } $ file = $ request -> file ( 'product_image' ) ; $ file -> move ( public_path ( ) . '/product/images' , $ file -> getClientOriginalName ( ) ) ; $ product_image = $ file -> getClientOriginalName ( ) ; $ products -> product_image = $ product_image ; } if ( $ request -> product_code != '' && $ request -> product_code != $ products -> product_code ) { if ( $ products -> barcode != '' ) { $ barcode_path = public_path ( ) . '/product/barcodes/' . $ product_code . 'jpg' ; unlink ( $ barcode_path ) ; } $ product_code = $ request -> product_code ; $ redColor = '255,0,0' ; $ generator = new Picqer \ Barcode \ BarcodeGeneratorJPG ( ) ; file_put_contents ( 'product/barcodes/' . $ product_code . '.jpg' , $ generator -> getBarcode ( $ product_code , $ generator :: TYPE_CODE_128 , 3 , 50 ) ) ; $ products -> barcode = $ product_code . '.jpg' ; } $ products -> product_name = $ request -> product_name ; $ products -> product_code = $ product_code ; $ products -> quantity = $ request -> quantity ; $ products -> price = $ request -> price ; $ products -> brand = $ request -> brand ; $ products -> alert_stock = $ request -> alert_stock ; $ products -> description = $ request -> description ; $ products -> save ( ) ; return redirect ( ) -> back ( ) -> with ( 'success' , 'product successfully created' ) ; return redirect ( ) -> back ( ) -> with ( 'success' , 'info successfully updated' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//image section //ending of adding of image to the form //product code section which is being used to generate the barcode in jpg format //end of barcode section //$product->update($request->all());