app/Http/Controllers/OrderDetailController.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)
    {
        $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 = new OrderDetail;            
               $orderdetail->desc = $request->desc;             
               $orderdetail->cost = $request->cost;             
               $orderdetail->price = $request->price;             
               $orderdetail->orderid = $request->orderid;             
               $orderdetail->save();            
               return back()->with('success','Successfully created order detail!');         
           }    
    }
public function store ( Request $ request ) { $ 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 = new OrderDetail ; $ orderdetail -> desc = $ request -> desc ; $ orderdetail -> cost = $ request -> cost ; $ orderdetail -> price = $ request -> price ; $ orderdetail -> orderid = $ request -> orderid ; $ orderdetail -> save ( ) ; return back ( ) -> with ( 'success' , 'Successfully created order detail!' ) ; } }
Store a newly created resource in storage.
Store a newly created 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            