title: laravel toggle button not sending value back to db ajax
body: <p>I'm using Laravel and ajax for the sending of request to update db. When 'is_active' has value of 1, toggle the checkbox will update the value of 'is_active' in db, but when 'is_active' has value of 1, toggle the checkbox will <strong>NOT</strong> update the value of 'is_active' in db. Besides that, I'm having trouble to retrieve the value of 'is_active' based on the id. And also why is my 'cancel' button not working? Did i miss out anything?</p>
  
  <p>This is how my html looks like:-</p>
  
  <pre><code>@foreach($system_functions as $function)
       @if($function-&gt;group_id == 1)
         &lt;input type="hidden" id="id" value="{{$function-&gt;id}}" /&gt;
            &lt;tr&gt;
                &lt;td&gt;{!! $function-&gt;name !!}&lt;/td&gt;
                &lt;td&gt;&lt;input class="toggle_status" type="checkbox" @if($function-&gt;is_active) checked @endif id="is_active" name="is_active" data-on="启用" data-off="禁用" value="{{$function-&gt;id}}" data-toggle="toggle"&gt;&lt;/td&gt;
            &lt;/tr&gt;
      @endif
  @endforeach
  </code></pre>
  
  <p>This is my js in the html file:-</p>
  
  <pre><code>@section('script')
  &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
          $('.toggle_status').change(function (e) {
              e.preventDefault();
              var is_active = 0;
              var id = $(this).attr('value');
  
  
              if ($(this).is(':checked')) {
                  is_active = 1;
              }
  
              $.ajax({
                  type: 'POST',
                  headers: {
                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                  },
                  url: '/admin/system-functions',
                  data: {
                      is_active: is_active,
                      id:  id
                  },
                  success: function (data) {
  
                      $.confirm({
                          title:'edit?',
                          content:'edit?',
                          buttons:{
                              confirm: {
                                  text: 'edit',
                                  btnClass: 'btn-danger',
                                  action: function () {
                                      $.alert(data['success']);
                                  }
                              },
                              cancel: {
                                  text: 'cancel',
                                  btnClass: 'btn-default'
                              }
                          }
                      });
                  }
              });
          });
      });
  &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p>this is my controller file </p>
  
  <pre><code>public function update(Request $request)
  {
      $id = Input::get('id');
      $function=SystemFunction::where('id',$id)-&gt;first();
      if($request-&gt;get('is_active')==='on'){
          $is_active=1;
      } else{
          $is_active=0;
      }
      $function-&gt;update([
          'is_active' =&gt; $is_active
      ]);
      return response()-&gt;json(['success' =&gt; '成功修改状态']);
  }
  </code></pre>