app/Http/Controllers/DrugController.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)
    {
       DB::beginTransaction();
       try{
           $drug =Drug::find($id);
           $drug->name = $request->input('name');
           $drug->drug_type_id = $request->input('type_id');
           $drug->qty_in_stock = $drug->qty_in_stock+ $request->input('receiving_stock');
           $drug->unit_of_pricing = $request->input('unit_of_pricing');
           if (\Request::has('no_of_tablet')){
               $drug->no_of_tablet  = $request->input('no_of_tablet');
               $drug->qty_in_tablet =  $drug->qty_in_tablet+$request->input('receiving_stock')*10;
           }
           $drug->retail_price = $request->input('retail_price');
           $drug->supplier_id = $request->input('supplier_id');
           $drug->cost_price = $request->input('cost_price');
           $drug->expiry_date = str_replace('/','-',$request->input('expiry_date'));
           $drug->user_id = Auth::user()->id;
           $drug->save();
           DB::commit();
           toastr()->success('Drug Updated');
       }catch (\Exception $exception){
           DB::rollBack();
           toastr()->warning('Something went wrong, Try again!');
       }
        return back();
    }
public function update ( Request $ request , $ id ) { DB :: beginTransaction ( ) ; try { $ drug = Drug :: find ( $ id ) ; $ drug -> name = $ request -> input ( 'name' ) ; $ drug -> drug_type_id = $ request -> input ( 'type_id' ) ; $ drug -> qty_in_stock = $ drug -> qty_in_stock + $ request -> input ( 'receiving_stock' ) ; $ drug -> unit_of_pricing = $ request -> input ( 'unit_of_pricing' ) ; if ( \ Request :: has ( 'no_of_tablet' ) ) { $ drug -> no_of_tablet = $ request -> input ( 'no_of_tablet' ) ; $ drug -> qty_in_tablet = $ drug -> qty_in_tablet + $ request -> input ( 'receiving_stock' ) * 10 ; } $ drug -> retail_price = $ request -> input ( 'retail_price' ) ; $ drug -> supplier_id = $ request -> input ( 'supplier_id' ) ; $ drug -> cost_price = $ request -> input ( 'cost_price' ) ; $ drug -> expiry_date = str_replace ( '/' , '-' , $ request -> input ( 'expiry_date' ) ) ; $ drug -> user_id = Auth :: user ( ) -> id ; $ drug -> save ( ) ; DB :: commit ( ) ; toastr ( ) -> success ( 'Drug Updated' ) ; } catch ( \ Exception $ exception ) { DB :: rollBack ( ) ; toastr ( ) -> warning ( 'Something went wrong, Try again!' ) ; } return back ( ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//                $drug->no_of_tablet = $request->input('no_of_tablet'); //        $drug->nhis_amount = $request->input('nhis_amount');