类Illuminate的实体\ V​​alidation \ Validator无法转换为字符串 [英] Object of class Illuminate\Validation\Validator could not be converted to string

查看:323
本文介绍了类Illuminate的实体\ V​​alidation \ Validator无法转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图帮助自己使用共享相同主题的类似线程,但它没有产生所需的结果。我还没理解在代码中需要修复什么才能生成错误。请帮帮忙。什么是正确的?谢谢。感谢。

I have tried to help myself using the similar threads that share the same topic but it did not yield the desired result. I'm yet to understand what needed to be fixed in the code making it to generate the error. Please kindly help out. What is to be put right? Thanks. Appreciate.

这是代码:

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');
        }
    }


推荐答案

您的问题在于这条线..

Your problem is with this line..

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

删除$ validator。

Remove the $validator.

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

这篇关于类Illuminate的实体\ V​​alidation \ Validator无法转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆