类Illuminate \ Validation \ Validator的对象无法转换为字符串

时间:2016-05-16 17:45:16

标签: html5 laravel-5.1 laravel-blade laravel-validation laravel-request

我还没理解在代码中需要修复什么才能生成错误。什么是正确的?

这是代码:

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 个答案:

答案 0 :(得分:1)

你的问题出在这条线上..

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

删除$ validator。

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