Laravel error Controller::index() does not exist

Posted on

Laravel error Controller::index() does not exist

In this article, there will be an information written on how to solve the problem simply arise when an error specified in the title ‘Controller::index() does not exist’. It can be shown on the following image :

Laravel error Controller::index() does not exist
Laravel error Controller::index() does not exist

As shown in the image above, there is specifically error mentioned on the page that in this context, a controller named TestController doesn’t have any index method. Off course the error is generated since the route defined in routes/web.php defined on executing TestController when part of the URL named ‘test’ is accessed. The following is the content of file named web.php located in routes folder :

Route::resource('test','TestController');

The URL accessed in this context is :

http://localhost/public/test/

For further information, below is the log’s content shown similar error :

[2017-04-24 13:49:28] local.ERROR: ReflectionException: Method App\Http\Controllers\TestController::index() does not exist in /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php:333
Stack trace:
#0 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php(333): ReflectionMethod->__construct('App\\Http\\Contro...', 'index')
#1 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(800): Illuminate\Routing\Route->signatureParameters('Illuminate\\Data...')
#2 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(39): Illuminate\Routing\Router->substituteImplicitBindings(Object(Illuminate\Routing\Route))
#3 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#4 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#5 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(65): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#6 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#7 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#8 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#9 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#11 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#12 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#14 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#15 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#17 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#18 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#19 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#20 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#21 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(655): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#22 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(629): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#23 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(607): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#24 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(268): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#25 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#26 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#27 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#28 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#29 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(150): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#31 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(117): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#32 /var/www/html/testing/laravel-project/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#33 {main}

So, to solve the problem, check the file named TestController.php. But before checking it further, to give an additional information, the controller itself is just created without having any additional content inserted by the following command execution :

user@hostname:/var/www/html/testing/laravel-project# php artisan make:controller TestController
TestController created successfully.
user@hostname:/var/www/html/testing/laravel-project#

So, in order to solve the problem, just eidt the file named ‘TestController.php’ and adds method named ‘index’ as shown below by editing the file which is normally located in folder ‘app/Http/Controller¬† :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
//
}

Edit the content of the file named ‘TestController.php’ which is normally located in ‘app/Http/Controller’ so that it will be presented as follows :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    //
        public function index(){
                return('index');
        }
}

Based on the above script, the content of the page with the URL specified previously will be shown as follows :

Laravel error Controller::index() does not exist
Laravel error Controller::index() does not exist

One thought on “Laravel error Controller::index() does not exist

Leave a Reply