Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anuzpandey's avatar

Yajra Datatables - Loads all the data from database on server but works well on local environment.

I have used this package for a quite a long time but I am getting a weird issue on a live server. On local environment the response from the controller is correct and response data count is correct for whatever I put in pageLength value. But in Live Server, it is fetching all 20,000+ records.

If I use 10 as a page length then the first query is fast i.e normal, but when i paginate to page 2, again all the records are fetched. and the response size is again huge.

Local - Response Size is 7kb Screenshot from Local

Live - Response Size is 80mb Screenshot from Live Server

-- BlogController.php

$articles = Article::query()
            ->with(['media', 'editor', 'categories', 'author', 'views'])
            ->select('articles.*')
            ->$scope();

return DataTables::of($articles)
            ->editColumn('title', function ($data) {
                    return '<div>' . $data->title . '</div>';
                })
            ->addIndexColumn()
            ->rawColumns(['title'])
            ->make(TRUE);

-- Blade File

$(document).ready(() => {
    let articleTable = $("#article-tables").DataTable({
        processing: true,
        serverSide: true,
        "scrollX": true,
        "scrollY": false,
        responsive: false,
	paging: true,
        pageLength: 50,
        ajax: {
            url: "{{ route('api.cms.article.datatables') }}",
            type: "GET",
	},
        columns: [
            {data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false},
            {data: 'title', name: 'title', orderable: false},
        ],
        "fnDrawCallback": function () {
            initSwitchToggler()
            initTooltip()
            initPopOver()
        }
    });
});

Operating System : Oracle Linux (Live) | MacOs (Local) PHP Version : 8.0.19 Laravel Version : 8.83 Laravel-Datatables Version: 1.5

0 likes
2 replies
Nakov's avatar

What's the ->$scope does it defaults to ->get() maybe so it loads all into memory?

anuzpandey's avatar

@Nakov No it returns builder only, which is $query->where('published', TRUE); OR $query->where('published', FALSE); Locally everything works file, even with fake 50K+ data.

Please or to participate in this conversation.