app/Http/Controllers/catalogController.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)
    {
        $catalog=new catalog;
        $catalogQuantity= new catalogQuantity;
        $quantityRemark=new quantityRemark;
        $catalog=$catalog::find($id);
        $this->validate($request, [
            'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
            'name' => 'required',
            'price' => 'required|numeric',
            'discount_status' => 'required|numeric',
            'removeQuantity' => 'required',
            'remarks' => 'required_unless:removeQuantity,0'
        ]);
        if ($request->hasFile('image')) {
            $path = $request->image->move(public_path('/images/catalog'), $request->image->getClientOriginalName());
            $catalog->image=$request->image->getClientOriginalName();
        }
        $catalog->category_id=$request->all()['category_id'];
        $catalog->name=$request->all()['name'];
        $catalog->price=$request->all()['price'];
        $catalog->discount_status=$request->all()['discount_status'];
        $catalog->show_as_inv=$request->all()['show_as_inv'];
        $catalog->show_as_product=$request->all()['show_as_product'];
        $catalog->status=1;
        $catalog->save();
        $catalogQuantityData=$catalogQuantity::where('catalog_id', $id)->get()->toArray();
        if($catalogQuantityData){
            $catalogQuantityid=$catalogQuantityData[0]['id'];
            $catalogQuantity=$catalogQuantity::find($catalogQuantityid);
        }
        $newQuantity=$catalogQuantityData[0]['quantity']-(int)$request->all()['removeQuantity'];
        if($newQuantity>=0){
            $catalogQuantity->quantity=$newQuantity;
            $catalogQuantity->save();
        }else{
            return back()->withInput()->with('error_message','Inventory quantity cannot be less than zero');
        }
        if((int)$request->all()['removeQuantity']>0){
            $quantityRemark->quantity_id=$catalogQuantityid;
            $quantityRemark->modified_quantity=(int)$request->all()['removeQuantity'];
            $quantityRemark->input_type=0;
            $quantityRemark->remarks=$request->all()['remarks'];
            $quantityRemark->user=auth::user()->name;
            $quantityRemark->save();
        }
        return redirect('catalog');
    }
public function update ( Request $ request , $ id ) { $ catalog = new catalog ; $ catalogQuantity = new catalogQuantity ; $ quantityRemark = new quantityRemark ; $ catalog = $ catalog :: find ( $ id ) ; $ this -> validate ( $ request , [ 'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048' , 'name' => 'required' , 'price' => 'required|numeric' , 'discount_status' => 'required|numeric' , 'removeQuantity' => 'required' , 'remarks' => 'required_unless:removeQuantity,0' ] ) ; if ( $ request -> hasFile ( 'image' ) ) { $ path = $ request -> image -> move ( public_path ( '/images/catalog' ) , $ request -> image -> getClientOriginalName ( ) ) ; $ catalog -> image = $ request -> image -> getClientOriginalName ( ) ; } $ catalog -> category_id = $ request -> all ( ) [ 'category_id' ] ; $ catalog -> name = $ request -> all ( ) [ 'name' ] ; $ catalog -> price = $ request -> all ( ) [ 'price' ] ; $ catalog -> discount_status = $ request -> all ( ) [ 'discount_status' ] ; $ catalog -> show_as_inv = $ request -> all ( ) [ 'show_as_inv' ] ; $ catalog -> show_as_product = $ request -> all ( ) [ 'show_as_product' ] ; $ catalog -> status = 1 ; $ catalog -> save ( ) ; $ catalogQuantityData = $ catalogQuantity :: where ( 'catalog_id' , $ id ) -> get ( ) -> toArray ( ) ; if ( $ catalogQuantityData ) { $ catalogQuantityid = $ catalogQuantityData [ 0 ] [ 'id' ] ; $ catalogQuantity = $ catalogQuantity :: find ( $ catalogQuantityid ) ; } $ newQuantity = $ catalogQuantityData [ 0 ] [ 'quantity' ] - ( int ) $ request -> all ( ) [ 'removeQuantity' ] ; if ( $ newQuantity >= 0 ) { $ catalogQuantity -> quantity = $ newQuantity ; $ catalogQuantity -> save ( ) ; } else { return back ( ) -> withInput ( ) -> with ( 'error_message' , 'Inventory quantity cannot be less than zero' ) ; } if ( ( int ) $ request -> all ( ) [ 'removeQuantity' ] > 0 ) { $ quantityRemark -> quantity_id = $ catalogQuantityid ; $ quantityRemark -> modified_quantity = ( int ) $ request -> all ( ) [ 'removeQuantity' ] ; $ quantityRemark -> input_type = 0 ; $ quantityRemark -> remarks = $ request -> all ( ) [ 'remarks' ] ; $ quantityRemark -> user = auth :: user ( ) -> name ; $ quantityRemark -> save ( ) ; } return redirect ( 'catalog' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .