user12380208
user12380208

Reputation: 531

In laravel how to use if /else in controller

I am trying to pass value from view to controller, but it not working it was sent only "APPROVED"

my view

<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> 

my controller

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

Upvotes: 2

Views: 2932

Answers (1)

Yasin Patel
Yasin Patel

Reputation: 5731

In option tag of select you haven't use value attribute. so it will pass null to a controller.

Change option tags as below :

<option value="APPROVED" style="color:green">WITH DIGITAL SIGNATURE</option>
<option value="NOT-APPROVED" style="color:green">WITHOUT DIGITAL SIGNATURE</option>

Change in your controller :

if($request->digital_signature == 'APPROVED'){
 // your code
}
elseif($request->digital_signature == 'NOT-APPROVED'){
// your code
}

Upvotes: 1

Related Questions