I am using datatable yajra package in my project lravel 5.1 and wants to get data through laravel eloquent this is my suggestion model code.
public function candidate()
{
return $this->belongsTo('App\Candidate', 'suggested_user');
}
And this is controller code.
public function getBCReport()
{
$candidates = \App\Suggestion::with('candidate')->get();
return Datatables::of($candidates)
->make(true);
}
And this is my view code:
<
div class="panel-body">
<div class="candidatereport">
<div class="table-responsive">
<table class="table display" id="table_id" cellspacing="0" width="100%">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</section>
<script>
$(function() {
$('#table_id').DataTable({
processing: true,
serverSide: true,
dataType: 'json',
ajax: '{!! route('datatables.candidatereport') !!}',
columns: [
{ data: 'candidate.fname', name: 'fname' },
{ data: 'candidate.lname', name: 'lname' },
]
});
});
</script>
In controller when I use this code
$candidates = \App\Suggestion::with('candidate');
According to datatable yajra documentation http://ift.tt/1ojrMaw it’s not working butt when I use with
$candidates = \App\Suggestion::with('candidate')->get();
Its working butt this is not according to datatable yajra documentation. Can any one tell what is the reason behind this. Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire