I have a jQuery DataTable which ought to show the Contact messages to the authenticated(logged in) users. I have a code and it works perfectly. But, I still want to fetch the data from a database using Ajax request in the DataTable. The problem is, I have no clue as to how to do it.
I am getting confused with the documentation. There is a data: and columns:. Not sure how to do it in Laravel.
Here are the codes (that are working fine, but without Ajax requests)
Blade
<div class="container m-5">
<table id="table_id" class="table table-striped table-bordered mydatatable m-5" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>Message</th>
<th>Asked On</th>
<th>Answered On</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach($msg as $key => $message)
<tr>
<th>{{$message->id}}</th>
<th>{{$message->message}}</th>
<th>{{$message->asked_on}}</th>
<th>{{$message->answered_on}}</th>
<th>{{$message->status}}</th>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Message</th>
<th>Asked On</th>
<th>Answered On</th>
<th>Status</th>
</tr>
</tfoot>
</table>
</div>
@include('commonview.footer')
<script type="text/javascript">
$('#table_id').DataTable( {
});
</script>
Controller
<div class="container m-5">
<table id="table_id" class="table table-striped table-bordered mydatatable m-5" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>Message</th>
<th>Asked On</th>
<th>Answered On</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach($msg as $key => $message)
<tr>
<th>{{$message->id}}</th>
<th>{{$message->message}}</th>
<th>{{$message->asked_on}}</th>
<th>{{$message->answered_on}}</th>
<th>{{$message->status}}</th>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Message</th>
<th>Asked On</th>
<th>Answered On</th>
<th>Status</th>
</tr>
</tfoot>
</table>
</div>
@include('commonview.footer')
<script type="text/javascript">
$('#table_id').DataTable( {
});
</script>