I am new to laravel. I want to fetch the data from database and put it to datatable. This is my html
<div class="tab-pane" id="th_days_client" >
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<i class="material-icons">flag</i>
{{ $title }}
</h4>
<span class="pull-right">
<i class="fa fa-fw fa-chevron-up clickable"></i>
<i class="fa fa-fw fa-times removepanel clickable"></i>
</span>
</div>
<div class="panel-body">
<div class="table-responsive">
<table id="th_days_client_data" class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
The jQuery for this is :
var th_days_client;
$(document).ready(function () {
th_days_client = $('#th_days_client_data').DataTable({
"processing": true,
"serverSide": true,
"order": [],
"columns":[
{"data":"name"},
{"data":"email"},
{"data":"mobile"},
{"data":"actions"}
],
"ajax": "{{ url('client') }}" + ((typeof $('#th_days_client_data').attr('data-id') != "undefined") ? "/" + $('#id').val() + "/" + $('#th_days_client_data').attr('data-id') : "/th_days_client_data")
});
});
controller Function for this is :
public function th_days_client_data(Datatables $datatables)
{
$clientObj = new Client;
$client = $clientObj->get()
->map(function ($client) {
return [
'id' => $client->id,
'name' => $client->first_name.' '.$client->last_name,
'email' => $client->email,
'mobile' => $client->mobile
];
});
return $datatables->collection($client)
->addColumn('actions', '@if(Sentinel::inRole(\'admin\'))
<a href="{{ url(\'client/\' . $id . \'/edit\' ) }}" title="{{ trans(\'table.edit\') }}">
<i class="fa fa-fw fa-pencil text-warning "></i> </a>
@endif
<a href="{{ url(\'client/\' . $id . \'/show\' ) }}" title="{{ trans(\'table.details\') }}" >
<i class="fa fa-fw fa-eye text-primary"></i> </a>
@if(Sentinel::inRole(\'admin\'))
<a href="javascript:void(0)" onclick="deleteClient({{$id}})" title="{{ trans(\'table.delete\') }}">
<i class="fa fa-fw fa-trash text-danger"></i> </a>
@endif')
->removeColumn('id')
->rawColumns(['actions'])->make();
}
When I am running this code then it is giving error :
DataTables warning: table id=th_days_client_data - Ajax error. For more information about this error, please see http://datatables.net/tn/7
How can I resolve this issue ?