当我提交带有值的表单时,它只是在我更新表单字段中的值后才第一次检查条件,它不检查if条件只检查表单验证规则并仅提交数据如何给出所有条件和验证规则,我在模型中添加了规则,即仅需要每个字段 这是我的控制器代码: public function addtaskdetail(){
$inputs=Input::all();
$data2 =DB::table('Task_Headers')->where('id','=',$inputs['TaskHeader_id'])->first();
$abc =$data2->Estimated_cost;
$dur=$data2->Duration;
$pcd=$data2->Planned_Completion_Date;
$xyz = $inputs['Unit_cost'];
$durtd=$inputs['Duration'];
$pcdtd=$inputs['Planned_Completion_Date'];
if($xyz>$abc){
Session::flash('flash_message','Unit cost must be less than estimated cost ');
}
if($pcdtd>$pcd){
Session::flash('flash_message1','planned completion date must be less than planned completi0n date in TaskHeader ');
}
if($durtd>$dur){
Session::flash('flash_message2','Duration must be less than Duration in TaskHeader ');
}
$validation = Validator::make($inputs, TaskDetail::$rules);
if($validation->fails()){
return Redirect::to('taskdetailaddform')->withErrors($validation)->withInput();
}else{
$input=Input::only('TaskHeader_id','description','Duration','Planned_Completion_Date','currency_code','Unit_cost','Vendor_id','status');
$data=new TaskDetail;
$data->TaskHeader_id = $input['TaskHeader_id'];
$data->description = $input['description'];
$data->Duration = $input['Duration'];
$data->Planned_Completion_Date = $input['Planned_Completion_Date'];
$data->currency_code = $input['currency_code'];
$data->Unit_cost = $input['Unit_cost'];
$data->Vendor_id = $input['Vendor_id'];
$data->status = $input['status'];
$data->save();
return redirect('taskdetailinfo');
}}
非常感谢任何帮助。
感谢您修复我的语法错误和建议。 我找到了我发布的那个问题的解决方案。