Object of class Illuminate\Validation\Validator co

2019-09-12 17:01发布

I'm yet to understand what needed to be fixed in the code making it to generate the error. What is to be put right?

This is the code:

public function store(Request $request){

        $validator = Validator::make($request->all(), [
                'user_id'                       => 'required|numeric',
                'company_id'                    => 'required|numeric',
                'product_id'                    => 'required|numeric',

                'tankerTotankerDesc'            => 'alpha_num|min:5',
                'tankerTakeOverDesc'            => 'alpha_num|min:5',
                'costFreightInsuranceDesc'      => 'alpha_num|min:5',
                'freightOnBoardDesc'            => 'alpha_num|min:5',

                'tankerTotankerPrice'           => 'numeric|required_with:tankerTotankerDesc',
                'tankerTakeOverPrice'           => 'numeric|required_with:tankerTakeOverDesc',
                'costFreightInsurancePrice'     => 'numeric|required_with:costFreightInsuranceDesc',
                'freightOnBoardPrice'           => 'numeric|required_with:freightOnBoardDesc',

                'optional_procedure'            => 'alpha_num|min:5',
                'optional_procedure_price'      => 'numeric|required_with:optional_procedure',
                'business_type'                 => 'required'
        ]);

        if ($validator->fails()) {
            redirect()->route('productUniqueCreate', $validator)->with('message', 'Record successfully created');
        }else{
           $product_id = $request->product_id;       
           $procurementUnique = ProcurementUnique::firstOrNew(array('product_id'=>$product_id));
           $procurementUnique->user_id     = $user_id;
           $procurementUnique->company_id  = $request->company_id;
           $procurementUnique->product_id  = $product_id;
           $procurementUnique->productname = $request->productname;

           $procurementUnique->ttt_description    = $request->tankerTotankerDesc;
           $procurementUnique->tto_description    = $request->tankerTakeOverDesc;
           $procurementUnique->cif_description    = $request->costFreightInsuranceDesc;
           $procurementUnique->fob_description    = $request->freightOnBoardDesc;
           $procurementUnique->optional_procedure = $request->optional_procedure;

           $procurementUnique->ttt_price    = $request->tankerTotankerPrice;
           $procurementUnique->tto_price    = $request->tankerTakeOverPrice;
           $procurementUnique->cif_price    = $request->costFreightInsurancePrice;
           $procurementUnique->fob_price    = $request->freightOnBoardPrice;
           $procurementUnique->optional_procedure_price = $request->optional_procedure_price;

           $procurementUnique->business_type    = $request->business_type;
           $procurementUnique->save();

            return redirect()->route('productUniqueCreate', $product_id)->with('message', 'Record successfully created');
        }
    }

1条回答
Bombasti
2楼-- · 2019-09-12 17:58

Your problem is with this line..

redirect()->route('productUniqueCreate', $validator)->with('message', 'Record successfully created');

Remove the $validator.

redirect()->route('productUniqueCreate')->with('message', 'Record successfully created')->withErrors($validator);
查看更多
登录 后发表回答