在 laravel 中如何在控制器中使用 if /else

我正在尝试将值从视图传递到控制器,但它不起作用,它只发送了“已批准”


我的观点


<div class="form-group row">

  <label for="colFormLabelLg" class="col-md-2 col-sm-3 control-label control-label-lg"><b>DIGITAL SIGNATURE</b></label>

  <div class="col-md-3">

    <div  class="form-group" id=digital_signature > 

      <select  class="form-control" name="digital_signature" value="{{ old('digital_signature') }}" required autofocus  >

        <option value=""></option>

        <option style="color:green">WITH DIGITAL SIGNATURE</option>

        <option style="color:green">WITHOUT DIGITAL SIGNATURE</option>

      </select>

    </div>

  </div>

</div> 

我的控制器


public function new_approvel_update(Request $request, $id)

{  

    if($request->digital_signature == 'WITH DIGITAL SIGNATURE')

    {

          $input= Student::Where('delete_status','NOT DELETED')->find($id);

          $input['center_approved'] = strtoupper ('APPROVED');

          $input['date_of_join'] = $request->date_of_join;   

    } elseif($request->digital_signature == 'WITHOUT DIGITAL SIGNATURE') {     

          $input= Student::Where('delete_status','NOT DELETED')->find($id);

          $input['center_approved'] = strtoupper ('NOT-APPROVED');

          $input['date_of_join'] = $request->date_of_join;

    }


  $certificate->save();


  return redirect('new_application')->with('success',' APPLICATION APPROVED SUCCESSFULLY .');

}


红糖糍粑
浏览 114回答 1
1回答

至尊宝的传说

在您的option标签中select没有使用value属性。所以它会将 null 传递给控制器。更改选项标签如下:<option value="APPROVED" style="color:green">WITH DIGITAL SIGNATURE</option><option value="NOT-APPROVED" style="color:green">WITHOUT DIGITAL SIGNATURE</option>更改您的控制器:if($request->digital_signature == 'APPROVED'){&nbsp;// your code}elseif($request->digital_signature == 'NOT-APPROVED'){// your code}
打开App,查看更多内容
随时随地看视频慕课网APP