Use Modal show checked my View and value 1 or 0 my database in Laravel 5.5









up vote
0
down vote

favorite












I use Laravel 5.5. I use Modal Edit in Index View. I want to save the state of a checkbox in a database, type Boolean, if checked 1 else 0. However, when checked the checkbox and confirm, In my view do not checked with value =1, I have check the database does not match the operation I checked.here is my code:
MyController



public function index(Request $request)
$persons = Person::get();
return view('persons.view_persons',compact('persons'));

public function editPerson(request $request){
$persons = Person::find ($request->id);
$persons->namethon = $request->namethon;
if (!isset($request['12']))
$persons->n2012= 0;
else $persons->n2012= 1;

if (!isset($request['13']))
$persons->n2013= 0;
else $persons->n2013= 1;

$persons->save();
return response()->json($persons);


MyView view_persons use Modal edit ajax



<table class="table table-striped table-bordered table-hover dataTable no-footer"
id="editable_table" role="grid">
<thead>
<tr role="row">
<th >STT
<th>Name THon</th>
<th >Actions</th>
</tr>
</thead>
<tbody>
csrf_field()
<?php $no=1; ?>
@foreach ($persons as $value)
<tr id="post$value->id" role="row" class="even">
<td> $no++ </td>
<td> $value->namethon </td>

<td>
<a href="#" class="show-modal btn btn-warning glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013" >
<i class="fa fa-eye"></i>
</a>
<a href="#" class="edit-modal btn btn-success glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013"
<i class="fa fa-pencil"></i>
</a>
<a href="#" class="delete-modal btn btn-danger glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013"
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@include('persons.edit_delete')


My Edit Modal edit_delete.blade.php



<div id="myModal"class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-success">
<button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="modal">
<div class="form-group row">
<div class="col-12 col-lg-3 text-lg-right">
<label class="col-form-label" for="id">ID: </label>
</div>
<div class="col-12 col-md-6 col-lg-8">
<div class="input-group">
<input type="text" class="form-control form-control-md" id="fid" disabled>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-12 col-lg-3 text-lg-right">
<label class="col-form-label" for="">Name T/TDP:</label>
</div>
<div class="col-12 col-md-6 col-lg-8">
<div class="input-group">
<input type="name" class="form-control form-control-md" id="t">
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-1"></div>
<div class="col-10">
<label class="custom-control custom-checkbox">
<input type="hidden" class="custom-control-input" id="12" value="0" name="12">
<input type="checkbox" class="custom-control-input" id="12" value="1" name="12" ?> >
<span class="custom-control-indicator"></span>
<span class="custom-control-description">2012</span>
</label>|
<label class="custom-control custom-checkbox">
<input type="hidden" class="custom-control-input" id="13" value="0" name="13">
<input type="checkbox" class="custom-control-input" id="13" value="1" name="13">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">2013</span>
</label>|
</div>


My Ajax Modal



$(document).on('click', '.edit-modal', function() 
$('#footer_action_button').text(" Update Post");
$('#footer_action_button').addClass('fa-check');
$('#footer_action_button').removeClass('fa-trash');
$('.actionBtn').addClass('btn-success');
$('.actionBtn').removeClass('btn-danger');
$('.actionBtn').addClass('edit');
$('.modal-title').text('Edit T/TDP');
$('.deleteContent').hide();
$('.form-horizontal').show();
$('#fid').val($(this).data('id'));
$('#t').val($(this).data('mynamethon'));
$('#12').val($(this).data('myn2012'));
$('#13').val($(this).data('myn2013'));
$('#myModal').modal('show');
);

$('.modal-footer').on('click', '.edit', function()

$.ajax(
type: 'POST',
url: 'editPerson',
data:
'_token': $('input[name=_token]').val(),
'id': $("#fid").val(),
'namethon': $('#t').val(),
'n2012':$('#12').val(),
'n2013':$('#13').val(),
,
success: function(data)
location.reload(true);

);
);


Thank you for viewing. Please help me.










share|improve this question

























    up vote
    0
    down vote

    favorite












    I use Laravel 5.5. I use Modal Edit in Index View. I want to save the state of a checkbox in a database, type Boolean, if checked 1 else 0. However, when checked the checkbox and confirm, In my view do not checked with value =1, I have check the database does not match the operation I checked.here is my code:
    MyController



    public function index(Request $request)
    $persons = Person::get();
    return view('persons.view_persons',compact('persons'));

    public function editPerson(request $request){
    $persons = Person::find ($request->id);
    $persons->namethon = $request->namethon;
    if (!isset($request['12']))
    $persons->n2012= 0;
    else $persons->n2012= 1;

    if (!isset($request['13']))
    $persons->n2013= 0;
    else $persons->n2013= 1;

    $persons->save();
    return response()->json($persons);


    MyView view_persons use Modal edit ajax



    <table class="table table-striped table-bordered table-hover dataTable no-footer"
    id="editable_table" role="grid">
    <thead>
    <tr role="row">
    <th >STT
    <th>Name THon</th>
    <th >Actions</th>
    </tr>
    </thead>
    <tbody>
    csrf_field()
    <?php $no=1; ?>
    @foreach ($persons as $value)
    <tr id="post$value->id" role="row" class="even">
    <td> $no++ </td>
    <td> $value->namethon </td>

    <td>
    <a href="#" class="show-modal btn btn-warning glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013" >
    <i class="fa fa-eye"></i>
    </a>
    <a href="#" class="edit-modal btn btn-success glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013"
    <i class="fa fa-pencil"></i>
    </a>
    <a href="#" class="delete-modal btn btn-danger glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013"
    <i class="fa fa-trash"></i>
    </a>
    </td>
    </tr>
    @endforeach
    </tbody>
    </table>
    @include('persons.edit_delete')


    My Edit Modal edit_delete.blade.php



    <div id="myModal"class="modal fade" role="dialog">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header bg-success">
    <button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title"></h4>
    </div>
    <div class="modal-body">
    <form class="form-horizontal" role="modal">
    <div class="form-group row">
    <div class="col-12 col-lg-3 text-lg-right">
    <label class="col-form-label" for="id">ID: </label>
    </div>
    <div class="col-12 col-md-6 col-lg-8">
    <div class="input-group">
    <input type="text" class="form-control form-control-md" id="fid" disabled>
    </div>
    </div>
    </div>
    <div class="form-group row">
    <div class="col-12 col-lg-3 text-lg-right">
    <label class="col-form-label" for="">Name T/TDP:</label>
    </div>
    <div class="col-12 col-md-6 col-lg-8">
    <div class="input-group">
    <input type="name" class="form-control form-control-md" id="t">
    </div>
    </div>
    </div>
    <div class="form-group row">
    <div class="col-sm-1"></div>
    <div class="col-10">
    <label class="custom-control custom-checkbox">
    <input type="hidden" class="custom-control-input" id="12" value="0" name="12">
    <input type="checkbox" class="custom-control-input" id="12" value="1" name="12" ?> >
    <span class="custom-control-indicator"></span>
    <span class="custom-control-description">2012</span>
    </label>|
    <label class="custom-control custom-checkbox">
    <input type="hidden" class="custom-control-input" id="13" value="0" name="13">
    <input type="checkbox" class="custom-control-input" id="13" value="1" name="13">
    <span class="custom-control-indicator"></span>
    <span class="custom-control-description">2013</span>
    </label>|
    </div>


    My Ajax Modal



    $(document).on('click', '.edit-modal', function() 
    $('#footer_action_button').text(" Update Post");
    $('#footer_action_button').addClass('fa-check');
    $('#footer_action_button').removeClass('fa-trash');
    $('.actionBtn').addClass('btn-success');
    $('.actionBtn').removeClass('btn-danger');
    $('.actionBtn').addClass('edit');
    $('.modal-title').text('Edit T/TDP');
    $('.deleteContent').hide();
    $('.form-horizontal').show();
    $('#fid').val($(this).data('id'));
    $('#t').val($(this).data('mynamethon'));
    $('#12').val($(this).data('myn2012'));
    $('#13').val($(this).data('myn2013'));
    $('#myModal').modal('show');
    );

    $('.modal-footer').on('click', '.edit', function()

    $.ajax(
    type: 'POST',
    url: 'editPerson',
    data:
    '_token': $('input[name=_token]').val(),
    'id': $("#fid").val(),
    'namethon': $('#t').val(),
    'n2012':$('#12').val(),
    'n2013':$('#13').val(),
    ,
    success: function(data)
    location.reload(true);

    );
    );


    Thank you for viewing. Please help me.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I use Laravel 5.5. I use Modal Edit in Index View. I want to save the state of a checkbox in a database, type Boolean, if checked 1 else 0. However, when checked the checkbox and confirm, In my view do not checked with value =1, I have check the database does not match the operation I checked.here is my code:
      MyController



      public function index(Request $request)
      $persons = Person::get();
      return view('persons.view_persons',compact('persons'));

      public function editPerson(request $request){
      $persons = Person::find ($request->id);
      $persons->namethon = $request->namethon;
      if (!isset($request['12']))
      $persons->n2012= 0;
      else $persons->n2012= 1;

      if (!isset($request['13']))
      $persons->n2013= 0;
      else $persons->n2013= 1;

      $persons->save();
      return response()->json($persons);


      MyView view_persons use Modal edit ajax



      <table class="table table-striped table-bordered table-hover dataTable no-footer"
      id="editable_table" role="grid">
      <thead>
      <tr role="row">
      <th >STT
      <th>Name THon</th>
      <th >Actions</th>
      </tr>
      </thead>
      <tbody>
      csrf_field()
      <?php $no=1; ?>
      @foreach ($persons as $value)
      <tr id="post$value->id" role="row" class="even">
      <td> $no++ </td>
      <td> $value->namethon </td>

      <td>
      <a href="#" class="show-modal btn btn-warning glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013" >
      <i class="fa fa-eye"></i>
      </a>
      <a href="#" class="edit-modal btn btn-success glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013"
      <i class="fa fa-pencil"></i>
      </a>
      <a href="#" class="delete-modal btn btn-danger glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013"
      <i class="fa fa-trash"></i>
      </a>
      </td>
      </tr>
      @endforeach
      </tbody>
      </table>
      @include('persons.edit_delete')


      My Edit Modal edit_delete.blade.php



      <div id="myModal"class="modal fade" role="dialog">
      <div class="modal-dialog">
      <div class="modal-content">
      <div class="modal-header bg-success">
      <button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title"></h4>
      </div>
      <div class="modal-body">
      <form class="form-horizontal" role="modal">
      <div class="form-group row">
      <div class="col-12 col-lg-3 text-lg-right">
      <label class="col-form-label" for="id">ID: </label>
      </div>
      <div class="col-12 col-md-6 col-lg-8">
      <div class="input-group">
      <input type="text" class="form-control form-control-md" id="fid" disabled>
      </div>
      </div>
      </div>
      <div class="form-group row">
      <div class="col-12 col-lg-3 text-lg-right">
      <label class="col-form-label" for="">Name T/TDP:</label>
      </div>
      <div class="col-12 col-md-6 col-lg-8">
      <div class="input-group">
      <input type="name" class="form-control form-control-md" id="t">
      </div>
      </div>
      </div>
      <div class="form-group row">
      <div class="col-sm-1"></div>
      <div class="col-10">
      <label class="custom-control custom-checkbox">
      <input type="hidden" class="custom-control-input" id="12" value="0" name="12">
      <input type="checkbox" class="custom-control-input" id="12" value="1" name="12" ?> >
      <span class="custom-control-indicator"></span>
      <span class="custom-control-description">2012</span>
      </label>|
      <label class="custom-control custom-checkbox">
      <input type="hidden" class="custom-control-input" id="13" value="0" name="13">
      <input type="checkbox" class="custom-control-input" id="13" value="1" name="13">
      <span class="custom-control-indicator"></span>
      <span class="custom-control-description">2013</span>
      </label>|
      </div>


      My Ajax Modal



      $(document).on('click', '.edit-modal', function() 
      $('#footer_action_button').text(" Update Post");
      $('#footer_action_button').addClass('fa-check');
      $('#footer_action_button').removeClass('fa-trash');
      $('.actionBtn').addClass('btn-success');
      $('.actionBtn').removeClass('btn-danger');
      $('.actionBtn').addClass('edit');
      $('.modal-title').text('Edit T/TDP');
      $('.deleteContent').hide();
      $('.form-horizontal').show();
      $('#fid').val($(this).data('id'));
      $('#t').val($(this).data('mynamethon'));
      $('#12').val($(this).data('myn2012'));
      $('#13').val($(this).data('myn2013'));
      $('#myModal').modal('show');
      );

      $('.modal-footer').on('click', '.edit', function()

      $.ajax(
      type: 'POST',
      url: 'editPerson',
      data:
      '_token': $('input[name=_token]').val(),
      'id': $("#fid").val(),
      'namethon': $('#t').val(),
      'n2012':$('#12').val(),
      'n2013':$('#13').val(),
      ,
      success: function(data)
      location.reload(true);

      );
      );


      Thank you for viewing. Please help me.










      share|improve this question













      I use Laravel 5.5. I use Modal Edit in Index View. I want to save the state of a checkbox in a database, type Boolean, if checked 1 else 0. However, when checked the checkbox and confirm, In my view do not checked with value =1, I have check the database does not match the operation I checked.here is my code:
      MyController



      public function index(Request $request)
      $persons = Person::get();
      return view('persons.view_persons',compact('persons'));

      public function editPerson(request $request){
      $persons = Person::find ($request->id);
      $persons->namethon = $request->namethon;
      if (!isset($request['12']))
      $persons->n2012= 0;
      else $persons->n2012= 1;

      if (!isset($request['13']))
      $persons->n2013= 0;
      else $persons->n2013= 1;

      $persons->save();
      return response()->json($persons);


      MyView view_persons use Modal edit ajax



      <table class="table table-striped table-bordered table-hover dataTable no-footer"
      id="editable_table" role="grid">
      <thead>
      <tr role="row">
      <th >STT
      <th>Name THon</th>
      <th >Actions</th>
      </tr>
      </thead>
      <tbody>
      csrf_field()
      <?php $no=1; ?>
      @foreach ($persons as $value)
      <tr id="post$value->id" role="row" class="even">
      <td> $no++ </td>
      <td> $value->namethon </td>

      <td>
      <a href="#" class="show-modal btn btn-warning glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013" >
      <i class="fa fa-eye"></i>
      </a>
      <a href="#" class="edit-modal btn btn-success glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013"
      <i class="fa fa-pencil"></i>
      </a>
      <a href="#" class="delete-modal btn btn-danger glow_button" data-id="$value->id" data-mynamethon="$value->namethon" data-myn2012="$value->n2012" data-myn2013="$value->n2013"
      <i class="fa fa-trash"></i>
      </a>
      </td>
      </tr>
      @endforeach
      </tbody>
      </table>
      @include('persons.edit_delete')


      My Edit Modal edit_delete.blade.php



      <div id="myModal"class="modal fade" role="dialog">
      <div class="modal-dialog">
      <div class="modal-content">
      <div class="modal-header bg-success">
      <button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title"></h4>
      </div>
      <div class="modal-body">
      <form class="form-horizontal" role="modal">
      <div class="form-group row">
      <div class="col-12 col-lg-3 text-lg-right">
      <label class="col-form-label" for="id">ID: </label>
      </div>
      <div class="col-12 col-md-6 col-lg-8">
      <div class="input-group">
      <input type="text" class="form-control form-control-md" id="fid" disabled>
      </div>
      </div>
      </div>
      <div class="form-group row">
      <div class="col-12 col-lg-3 text-lg-right">
      <label class="col-form-label" for="">Name T/TDP:</label>
      </div>
      <div class="col-12 col-md-6 col-lg-8">
      <div class="input-group">
      <input type="name" class="form-control form-control-md" id="t">
      </div>
      </div>
      </div>
      <div class="form-group row">
      <div class="col-sm-1"></div>
      <div class="col-10">
      <label class="custom-control custom-checkbox">
      <input type="hidden" class="custom-control-input" id="12" value="0" name="12">
      <input type="checkbox" class="custom-control-input" id="12" value="1" name="12" ?> >
      <span class="custom-control-indicator"></span>
      <span class="custom-control-description">2012</span>
      </label>|
      <label class="custom-control custom-checkbox">
      <input type="hidden" class="custom-control-input" id="13" value="0" name="13">
      <input type="checkbox" class="custom-control-input" id="13" value="1" name="13">
      <span class="custom-control-indicator"></span>
      <span class="custom-control-description">2013</span>
      </label>|
      </div>


      My Ajax Modal



      $(document).on('click', '.edit-modal', function() 
      $('#footer_action_button').text(" Update Post");
      $('#footer_action_button').addClass('fa-check');
      $('#footer_action_button').removeClass('fa-trash');
      $('.actionBtn').addClass('btn-success');
      $('.actionBtn').removeClass('btn-danger');
      $('.actionBtn').addClass('edit');
      $('.modal-title').text('Edit T/TDP');
      $('.deleteContent').hide();
      $('.form-horizontal').show();
      $('#fid').val($(this).data('id'));
      $('#t').val($(this).data('mynamethon'));
      $('#12').val($(this).data('myn2012'));
      $('#13').val($(this).data('myn2013'));
      $('#myModal').modal('show');
      );

      $('.modal-footer').on('click', '.edit', function()

      $.ajax(
      type: 'POST',
      url: 'editPerson',
      data:
      '_token': $('input[name=_token]').val(),
      'id': $("#fid").val(),
      'namethon': $('#t').val(),
      'n2012':$('#12').val(),
      'n2013':$('#13').val(),
      ,
      success: function(data)
      location.reload(true);

      );
      );


      Thank you for viewing. Please help me.







      laravel checkbox modal-dialog checked






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Nguyen thanh Duc

      42




      42



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237270%2fuse-modal-show-checked-my-view-and-value-1-or-0-my-database-in-laravel-5-5%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237270%2fuse-modal-show-checked-my-view-and-value-1-or-0-my-database-in-laravel-5-5%23new-answer', 'question_page');

          );

          Post as a guest














































































          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3