app/Http/Controllers/OrderDetailController.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)
    {
         $input = $request->all();                  
         $rules = array(             
             'desc' => 'required',             
             'cost' => 'required|numeric',             
             'price' => 'required|numeric',             
             'orderid' => 'required|numeric',         
             ); 
         $messages = [            
             'desc.required' => 'Please input the Description',         
             'cost.required' => 'Please input the Cost',          
             'cost.numeric' => 'Please input the Cost in correct format',        
             'price.required' => 'Please input the Price',          
             'price.numeric' => 'Please input the Price in correct format',       
             'orderid.required' => 'Please input the Order ID',           
             'orderid.numeric' => 'Please input the Order ID in correct format',         
             ];   
         $validator = Validator::make($input, $rules, $messages);                 
         if ($validator->fails()) {             
             return Redirect::to('orderdetails/create')>withErrors($validator);        
             } else {       
             $orderdetail = OrderDetail::find($id);         
             $orderdetail->desc = $request->desc; 
             $orderdetail->cost = $request->cost;       
             $orderdetail->price = $request->price;      
             $orderdetail->orderid = $request->orderid;       
             $orderdetail->save();         
             return back()->with('success','Successfully updated order detail!');     
             } 
    }
public function update ( Request $ request , $ id ) { $ input = $ request -> all ( ) ; $ rules = array ( 'desc' => 'required' , 'cost' => 'required|numeric' , 'price' => 'required|numeric' , 'orderid' => 'required|numeric' , ) ; $ messages = [ 'desc.required' => 'Please input the Description' , 'cost.required' => 'Please input the Cost' , 'cost.numeric' => 'Please input the Cost in correct format' , 'price.required' => 'Please input the Price' , 'price.numeric' => 'Please input the Price in correct format' , 'orderid.required' => 'Please input the Order ID' , 'orderid.numeric' => 'Please input the Order ID in correct format' , ] ; $ validator = Validator :: make ( $ input , $ rules , $ messages ) ; if ( $ validator -> fails ( ) ) { return Redirect :: to ( 'orderdetails/create' ) > withErrors ( $ validator ) ; } else { $ orderdetail = OrderDetail :: find ( $ id ) ; $ orderdetail -> desc = $ request -> desc ; $ orderdetail -> cost = $ request -> cost ; $ orderdetail -> price = $ request -> price ; $ orderdetail -> orderid = $ request -> orderid ; $ orderdetail -> save ( ) ; return back ( ) -> with ( 'success' , 'Successfully updated order detail!' ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .
// Get the submitted input          // Create validation rules, please refer to https://laravel.com/docs/7.x/validation#availablevalidationrules for more details          // Create customized validation messages         // Perform insert order action when validation pass or return to the index page if validation fails         // Create a Order instance and configure the values before insert action           