0

我試圖幫助自己使用共享相同主題的類似線程,但它沒有產生期望的結果。我還沒有理解代碼中需要修正哪些內容才能生成錯誤。請請幫忙。什麼是正確的?謝謝。欣賞。類Illuminate Validation Validator的對象無法轉換爲字符串

這是代碼:

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

你的問題是此行..

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

刪除$驗證。

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