title: How do I retrieve and display data by jquery Datatable in Laravel?
body: <p>Basically my intention is to fetch data from a database and display it using datatable API in laravel 5.2. However, I keep getting this error/notice <code>DataTables warning: table id=payments-table - Ajax error. For more information about this error,</code>please see<code>http://datatables.net/tn/7</code></p>
  
  <p>Kindly note I have set up my development environment as directed here: <a href="https://github.com/yajra/laravel-datatables" rel="nofollow">https://github.com/yajra/laravel-datatables</a> (jQuery DataTables API for Laravel 4|5 )</p>
  
  <p>My table name is <code>payments</code>.</p>
  
  <p>This is my routes code:</p>
  
  <pre><code>Route::controller('payments', 'admin\paymentsController', [
              'anyData'  =&gt; 'payments.data',
              'getIndex' =&gt; 'datatables',
          ]);
  </code></pre>
  
  <p>Then the controller in the admin folder code:</p>
  
  <pre><code>&lt;?php
  namespace App\Http\Controllers\admin;
  use App\Http\Controllers\Controller;
  use DB;
  use Illuminate\Http\Request;
  
  use App\Http\Requests;
  use Yajra\Datatables\Datatables;
  
  class paymentsController extends Controller
  {
      /**
       * Displays datatables front end view
       *
       * @return \Illuminate\View\View
       */
      public function getIndex()
      {
          return view('admin.payments', compact('payments'));
      }
  
      /**
       * Process datatables ajax request.
       *
       * @return \Illuminate\Http\JsonResponse
       */
      public function anyData()
      {
  
          return Datatables::of(payments::query())-&gt;make(true);
  
      }
  }
  </code></pre>
  
  <p>Then finally my view in the admin folder: </p>
  
  <pre><code>@extends('layouts.master')
  
  @section('content')
      &lt;table class="table table-bordered" id="payments-table"&gt;
          &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Id&lt;/th&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Amount&lt;/th&gt;
          &lt;/tr&gt;
          &lt;/thead&gt;
      &lt;/table&gt;
  @stop
  
  @push('scripts')
  &lt;script&gt;
      $(function() {
          $('#payments-table').DataTable({
              processing: true,
              serverSide: true,
              ajax: '{!! route('payments.data') !!}',
              columns: [
                  { data: 'id', name: 'id' },
                  { data: 'name', name: 'name' },
                  { data: 'amount', name: 'amount' },
                   ]
          });
      });
  &lt;/script&gt;
  @endpush
  </code></pre>
  
  <p>Please help me where is the mistake. Thanks.</p>