app/Http/Controllers/OrderController.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(
            'regno' => 'required',
            'regstate' => 'required',
            'custname' => 'required',
            'custphone' => 'required|numeric',
            'vehbrand' => 'required',
            'vehmodel' => 'required',
            'vehyear' => 'required|numeric',
            'serialno' => 'required'
        );
        $messages = [
            'regno.required' => 'Please input the Registration Number',
            'regstate.required' => 'Please input the Registration State',
            'custname.required' => 'Please input the Customer Name',
            'custphone.required' => 'Please input the Customer Phone',
            'custphone.numeric' => 'Please input the Customer Phone in correct format',
            'vehbrand.required' => 'Please input the Vehicle Brand',
            'vehmodel.required' => 'Please input the Vehicle Model',
            'vehyear.required' => 'Please input the Vehivle Manufacture Year',
            'vehyear.numeric' => 'Please input the Vehivle Manufacture Year in correct format',
            'serialno.required' => 'Please input the Vehicle Serial Nnumber',
        ];
        $validator = Validator::make($input, $rules,$messages);
        if ($validator->fails()) {
            return Redirect::to('orders/create')->withErrors($validator);
        } else {
            $order = new Order;
            $order->regno = $request->regno;
            $order->regstate = $request->regstate;
            $order->custname = $request->custname;
            $order->custphone = $request->custphone;
            $order->vehbrand = $request->vehbrand;
            $order->vehmodel = $request->vehmodel;
            $order->vehyear = $request->vehyear;
            $order->serialno = $request->serialno;
            $order->createddate = Carbon::now();
            $order->save();
            return back()->with('success','Successfully created order!');
        }
    }
public function store ( Request $ request ) { $ input = $ request -> all ( ) ; $ rules = array ( 'regno' => 'required' , 'regstate' => 'required' , 'custname' => 'required' , 'custphone' => 'required|numeric' , 'vehbrand' => 'required' , 'vehmodel' => 'required' , 'vehyear' => 'required|numeric' , 'serialno' => 'required' ) ; $ messages = [ 'regno.required' => 'Please input the Registration Number' , 'regstate.required' => 'Please input the Registration State' , 'custname.required' => 'Please input the Customer Name' , 'custphone.required' => 'Please input the Customer Phone' , 'custphone.numeric' => 'Please input the Customer Phone in correct format' , 'vehbrand.required' => 'Please input the Vehicle Brand' , 'vehmodel.required' => 'Please input the Vehicle Model' , 'vehyear.required' => 'Please input the Vehivle Manufacture Year' , 'vehyear.numeric' => 'Please input the Vehivle Manufacture Year in correct format' , 'serialno.required' => 'Please input the Vehicle Serial Nnumber' , ] ; $ validator = Validator :: make ( $ input , $ rules , $ messages ) ; if ( $ validator -> fails ( ) ) { return Redirect :: to ( 'orders/create' ) -> withErrors ( $ validator ) ; } else { $ order = new Order ; $ order -> regno = $ request -> regno ; $ order -> regstate = $ request -> regstate ; $ order -> custname = $ request -> custname ; $ order -> custphone = $ request -> custphone ; $ order -> vehbrand = $ request -> vehbrand ; $ order -> vehmodel = $ request -> vehmodel ; $ order -> vehyear = $ request -> vehyear ; $ order -> serialno = $ request -> serialno ; $ order -> createddate = Carbon :: now ( ) ; $ order -> save ( ) ; return back ( ) -> with ( 'success' , 'Successfully created order!' ) ; } }
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#available-validationrules 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