title: Route::controllers - Method [index] does not exist on [App\Http\Controllers
body: <p>I am running <code>PHP 7.0.25</code> and <code>Laravel Framework 5.5.25</code>.</p>
  
  <p>I would like to use the <a href="https://yajrabox.com/docs/laravel-datatables/master" rel="nofollow noreferrer">laravel datatables package</a> and followed the <a href="https://datatables.yajrabox.com/" rel="nofollow noreferrer">quickstart guide</a> and have exactly the same <code>controller</code> and <code>view</code>.</p>
  
  <p>However, when running my application I get the following error:</p>
  
  <pre><code>BadMethodCallException thrown with message "Method [index] does not exist on [App\Http\Controllers\DatatablesController]."
  
  Stacktrace:
  #51 BadMethodCallException in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:68
  #50 Illuminate\Routing\Controller:__call in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
  #49 call_user_func_array in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
  #48 Illuminate\Routing\Controller:callAction in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
  #47 Illuminate\Routing\ControllerDispatcher:dispatch in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Route.php:212
  #46 Illuminate\Routing\Route:runController in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Route.php:169
  #45 Illuminate\Routing\Route:run in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Router.php:658
  #44 Illuminate\Routing\Router:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
  #43 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
  #42 Illuminate\Routing\Middleware\SubstituteBindings:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #41 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #40 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:67
  #39 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #38 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #37 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
  #36 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #35 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #34 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:63
  #33 Illuminate\Session\Middleware\StartSession:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #32 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #31 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
  #30 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #29 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #28 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:59
  #27 Illuminate\Cookie\Middleware\EncryptCookies:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #26 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #25 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
  #24 Illuminate\Pipeline\Pipeline:then in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Router.php:660
  #23 Illuminate\Routing\Router:runRouteWithinStack in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Router.php:635
  #22 Illuminate\Routing\Router:runRoute in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Router.php:601
  #21 Illuminate\Routing\Router:dispatchToRoute in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Router.php:590
  #20 Illuminate\Routing\Router:dispatch in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
  #19 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
  #18 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/fideloper/proxy/src/TrustProxies.php:56
  #17 Fideloper\Proxy\TrustProxies:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #15 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
  #14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #12 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
  #11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #9 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
  #8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #6 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:46
  #5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
  #4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  #3 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
  #2 Illuminate\Pipeline\Pipeline:then in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
  #1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
  #0 Illuminate\Foundation\Http\Kernel:handle in /home/ubuntu/workspace/public/index.php:55
  </code></pre>
  
  <p>I expect that this error is coming from my route configuration, which I changed to <code>Route::resource</code> instead, as mentioned in the <a href="https://datatables.yajrabox.com/" rel="nofollow noreferrer">quickstart guide</a>, of the deprecated - since laravel 5.3 - <code>Route::controllers</code>:</p>
  
  <pre><code>Route::resource('datatables', 'DatatablesController', [
      'anyData'  =&gt; 'datatables.data',
      'getIndex' =&gt; 'datatables',
  ]);
  </code></pre>
  
  <p>Any suggestions how to write the route properly?</p>
  
  <p>PS.: I already used <code>composer dumpautoload</code>, <code>composer install</code> &amp; <code>composer update</code> and it does not change the error</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>My current Controller looks like the following:</p>
  
  <pre><code>namespace App\Http\Controllers;
  
  use App\Http\Requests;
  use App\User;
  use Yajra\Datatables\Datatables;
  
  class DatatablesController extends Controller
  {
      /**
       * Displays datatables front end view
       *
       * @return \Illuminate\View\View
       */
      public function getIndex()
      {
          return view('datatables.index');
      }
  
      /**
       * Process datatables ajax request.
       *
       * @return \Illuminate\Http\JsonResponse
       */
      public function anyData()
      {
          return Datatables::of(User::query())-&gt;make(true);
      }
  }
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>@extends('layouts.master')
  
  @section('content')
      &lt;table class="table table-bordered" id="users-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;Email&lt;/th&gt;
                  &lt;th&gt;Created At&lt;/th&gt;
                  &lt;th&gt;Updated At&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
      &lt;/table&gt;
  @stop
  
  @push('scripts')
  &lt;script&gt;
  $(function() {
      $('#users-table').DataTable({
          processing: true,
          serverSide: true,
          ajax: '{!! route('datatables.data') !!}',
          columns: [
              { data: 'id', name: 'id' },
              { data: 'name', name: 'name' },
              { data: 'email', name: 'email' },
              { data: 'created_at', name: 'created_at' },
              { data: 'updated_at', name: 'updated_at' }
          ]
      });
  });
  &lt;/script&gt;
  @endpush
  </code></pre>