empty result set yajra datatable on large tables
<p>I have a <code>Question</code> Model by about <strong>30,000</strong> records like this:</p>

<pre><code>class Question extends Model
    {
        use SoftDeletes;

        protected $primaryKey = 'question_id';

        protected $fillable   = ['text', 'code', 'cat', 'answer', 'confirmed', 'is_private', 'email', 'parent', 'expert'];

        public function sub_questions ()
        {
            return $this-&gt;hasMany(Question::class, 'parent', 'question_id');
        }

        public function latest_sub_question ()
        {
            return $this-&gt;hasOne(Question::class, 'parent', 'question_id')-&gt;latest();
        }


    }
</code></pre>

<p>To show a list of all questions I'm using <a href="https://github.com/yajra/laravel-datatables" rel="nofollow noreferrer">yajra datatable</a> laravel package.</p>

<p>This is my js code :</p>

<pre><code>var allQuestionsTable =
$('#allQuestionsTable').DataTable({
                        processing: true,
                        serverSide: true,
                        "bSort": false,
                        "responsive": true,
                        ajax: {
                            url: '{!! route('admin.questionsDatatable') !!}'
                        },
                        columns: [
                            {data: 'checkbox'},
                            {data: 'code', name: 'code'},
                            {data: 'text', name: 'text'},
                            {data: 'created_at'},
                            {data: 'answer', name: 'answer'},
                            {data: 'expert'},
                            {data: 'confirmed'},
                            {data: 'actions'}
                        ]
                    });
</code></pre>

<p>And in the back-end I wrote this function: </p>

<pre><code>public function questionsDatatable (Request $request)
        {
            $questions = Question::with('latest_sub_question')-&gt;whereNull('parent');

            $datatable = app('datatables')-&gt;of($questions)
                -&gt;addColumn('checkbox', '&lt;input type="checkbox" name="item_id[]" value="{{$question_id}}" id="Check_{{$question_id}}"&gt;');

                //other column modifications comes here

            return $datatable-&gt;make(true);
        }
</code></pre>

<p>First when my table had A few rows all things worked fine but when I added a large number of new records, <code>questionsDatatable</code> return empty value and cause datatables return an alert error.</p>

<p>what is problem ? and is there any parameter that can use to solve this problem?</p>

<p><strong>Update :</strong> </p>

<p>I changed <code>questionsDatatable</code> method to below and used simple query builders but it cannot return all records and return empty set :</p>

<pre><code>public function questionsDatatable (Request $request)
{

            $questions = DB::table('questions')-&gt;select(['question_id'])-&gt;get();

            return $questions-&gt;get();
}
</code></pre>