app/Http/Controllers/ProductController.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)
    {
        $this->validate($request,[
            'khName'       =>'required',
            'enName'        => 'required',
            'productCode'       =>'required',
            'productBarcode'        => 'required',
            'category_id'   => 'required',
        ],[
            'khName.required' =>'Khmer name required',
            'enName.required' =>'English name required',
            'productCode.required' =>'Product Barcode required',
            'productBarcode.required' =>'Product Barcode required',
            'category_id.required' =>'Category name required',
        ]);
        $pro = Product::find($id);
        $pro->productCode = trim($request->input('productCode'));
        $pro->productBarcode = trim($request->input('productBarcode'));
        $pro->khName = trim($request->input('khName'));
        $pro->enName = trim($request->input('enName'));
        if($request->input('category_id')!=null){
            $pro->category_id = trim($request->input('category_id'));
        }else{
            $pro->category_id =0;
        }
        if($request->input('branch_id')!=null){
            $pro->branch_id = trim($request->input('branch_id'));
        }else{
            $pro->branch_id =0;
        }
        $time =Carbon::now()->format('s');
        $mainphoto="default_photo.png";
        if($file =$request->file('imageEdit')){
            $photo=$time."_".$file->getClientOriginalName();
            $file->move('product_photo',$photo);
            $photoName = $pro->image;
            $pro->image = $photo;
            if($photoName!='default_photo.png'){
                unlink(public_path('product_photo/'.$photoName));
            }
        }
        $pro->user_id = Auth::user()->id;
        $pro->save();
        return redirect()->back();
    }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'khName' => 'required' , 'enName' => 'required' , 'productCode' => 'required' , 'productBarcode' => 'required' , 'category_id' => 'required' , ] , [ 'khName.required' => 'Khmer name required' , 'enName.required' => 'English name required' , 'productCode.required' => 'Product Barcode required' , 'productBarcode.required' => 'Product Barcode required' , 'category_id.required' => 'Category name required' , ] ) ; $ pro = Product :: find ( $ id ) ; $ pro -> productCode = trim ( $ request -> input ( 'productCode' ) ) ; $ pro -> productBarcode = trim ( $ request -> input ( 'productBarcode' ) ) ; $ pro -> khName = trim ( $ request -> input ( 'khName' ) ) ; $ pro -> enName = trim ( $ request -> input ( 'enName' ) ) ; if ( $ request -> input ( 'category_id' ) != null ) { $ pro -> category_id = trim ( $ request -> input ( 'category_id' ) ) ; } else { $ pro -> category_id = 0 ; } if ( $ request -> input ( 'branch_id' ) != null ) { $ pro -> branch_id = trim ( $ request -> input ( 'branch_id' ) ) ; } else { $ pro -> branch_id = 0 ; } $ time = Carbon :: now ( ) -> format ( 's' ) ; $ mainphoto = " default_photo.png " ; if ( $ file = $ request -> file ( 'imageEdit' ) ) { $ photo = $ time . " _ " . $ file -> getClientOriginalName ( ) ; $ file -> move ( 'product_photo' , $ photo ) ; $ photoName = $ pro -> image ; $ pro -> image = $ photo ; if ( $ photoName != 'default_photo.png' ) { unlink ( public_path ( 'product_photo/' . $ photoName ) ) ; } } $ pro -> user_id = Auth :: user ( ) -> id ; $ pro -> save ( ) ; return redirect ( ) -> back ( ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//get logo