have problem with eloquent and pagination+sorting

have problem with eloquent and pagination+sorting

alexblalexbl Posts: 1Questions: 1Answers: 0

Hi, I've make ajax request with datatable. smth like

$(document).ready(function() {
    var ss_dt = $('#screenshorts').DataTable( {
        "serverSide": true,
        "pagingType": "numbers",
        "ajax": {
            url: "{{ route('ajax.request') }}",
            type: "get",
        },
        columns: [
                { data: "id" },
        { data: "name"  },
            ]   
    } );
} );

On the server side I've make smth like:
public function ajaxRequst(Request $request)
{
$data = \App\Data->orderBy('name');
return DataTables::eloquent($data)
->make(true);
}
And had met the problem when try sort by any column from client's page. I get duplication of the rows in the datatable.
The solution was change eloquent -> to on the server side like this:

    public function ajaxRequst(Request $request) 
    {
        $data = \App\Data->orderBy('name');
        return DataTables::to($data)
                        ->make(true);
    }

But I think it's not good. I think this is bug.
Have you idea hot to make pagination, sort and use eloquent on server side?

This discussion has been closed.