app/Http/Controllers/ProductController.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 , Product $products)
    { 
     if ($request->hasFile('product_image')){
        $file = $request->file('product_image');
        $file->move(public_path(). '/product/images', $file->getClientOriginalName());
        $product_image = $file->getClientOriginalName();  
        $products->product_image = $product_image;      
    }
        $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::create($request->all());
      $products = new Product;
      $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->barcode = $product_code . '.jpg';
      $products->save();
      return redirect()->back()->with('success', 'product successfully created');
    }
public function store ( Request $ request , Product $ products ) { if ( $ request -> hasFile ( 'product_image' ) ) { $ file = $ request -> file ( 'product_image' ) ; $ file -> move ( public_path ( ) . '/product/images' , $ file -> getClientOriginalName ( ) ) ; $ product_image = $ file -> getClientOriginalName ( ) ; $ products -> product_image = $ product_image ; } $ 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 :: create ( $ request -> all ( ) ) ; $ products = new Product ; $ 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 -> barcode = $ product_code . '.jpg' ; $ products -> save ( ) ; return redirect ( ) -> back ( ) -> with ( 'success' , 'product successfully created' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//adding of image to the form using if statement  //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 //end of product code section which is being used to generate the barcode