I have one page called modals.blade.php in this I am performing an insert operation. This modal I am using on another page called view.blade.php. And the same modal I am using in other pages with different logic (the fields will be changing)
I need to call a function of view.blade.php from modals.blade.php after successful insertion. whether it is possible?
pages
modals.blade.php
<div class="modal fade" id="paymentModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<form id="paymentform" method="post">
{{ csrf_field() }}
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
modal body
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#paymentform').on('submit',function(event){
event.preventDefault();
var formdata = $('#paymentform').serialize();
$.ajax({
url:'{!! url('storepayment') !!}',
dataType:'json',
method:'post',
data: formdata,
success:function(data)
{
getAllPayments(); // Calling this function from another page
}
});
});
});
</script>
view.blade.php
@include('invoice.modals')
<div class="row ">
<div class="col-lg-12">
<table class="table table-bordered" id="contactdata" >
<thead>
<tr>
<th scope="col">SLNO</th>
<th scope="col">Invoice ID</th>
<th scope="col">Payment Method</th>
<th scope="col">Payment Date</th>
<th scope="col">Amount</th>
<th scope="col">Notes</th>
<th scope="col">edit</th>
</tr>
</thead>
</table>
</div>
</div>
<script>
$(function() {
getAllPayments();
function getAllPayments()
{
var invoiceid = $('#invoiceid').val();
$('#contactdata').DataTable({
processing: true,
serverSide: true,
"bDestroy": true,
"bAutoWidth": false,
ajax:{
"url" : '{!! url('payments') !!}',
data :{
'invoiceid' : invoiceid
},
},
columns: [
{ data:'DT_RowIndex'},
{ data: 'DT_RowData.data-invoice_id', name: 'invoice_id' },
{ data: 'payment_method', name: 'payment_method' },
{ data: 'payment_date', name: 'payment_date' },
{ data: 'amount', name: 'amount' },
{ data: 'notes', name: 'notes' },
]
});
}
});
Thank you in advance