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">×</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
add a comment |
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">×</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
add a comment |
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">×</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
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">×</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
laravel checkbox modal-dialog checked
asked yesterday
Nguyen thanh Duc
42
42
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password