Laravel Error Message : Class ‘App\Http\Controllers\Input’ not found

Posted on

This is an article discussing error triggered upon executing a page made using Laravel framework which is part of a web-application project built. The error can be found in the log file written and located at storage/logs. Normally, it is stored in a file named laravel.log or a file named with the addition of date attribute on it such as laravel-2017-05-02.log. The error is shown as below :

[2017-05-02 02:18:29] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App\Http\Controllers\Input' not found in /var/www/html/testing/laravel-project/app/Http/Controllers/TestController.php:36
Stack trace:
#0 [internal function]: App\Http\Controllers\TestController->store()
#1 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(55): call_user_func_array(Array, Array)
#2 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(44): Illuminate\Routing\Controller->callAction('store', Array)
#3 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php(189): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\TestController), 'store')
#4 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php(144): Illuminate\Routing\Route->runController()
#5 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(653): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#6 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#7 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#8 /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))
#9 /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))
#10 /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))
#11 /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))
#12 /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))
#13 /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))
#14 /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))

The error above is generated when an info or data inserted by some user via Input field is going to be extracted or to be retrieved. The Input field itself  is defined in a blade view file template.

To evade the error shown above, below is the step which can be done as follows  :

use Illuminate\Support\Facades\Input;

It is done by adding another definition to import Input class as shown above.  In this context, just add it in the Controller file to solve the problem.

Another method which can be used to resolve the error stated in the title of this article is by defining it in the application configuration file named app.php located in folder config. So, edit the file config/app.php and add an aliases for Input so that the import snippet code shown above can be omitted. Below is how to define it :

'Input' => Illuminate\Support\Facades\Input::class,

Just insert it in the Aliases Classes section’s definition :

'aliases' => [
        ...,
        'Html' => Collective\Html\HtmlFacade::class,
        'Input' => Illuminate\Support\Facades\Input::class,
        'Lang' => Illuminate\Support\Facades\Lang::class,
        ...,
],

It is basically defining an alias to load the class so that in the files created after, the import snippet code can be inserted and defined in those files in short or in an alias. It is because Laravel has already recognized the Input class based on the alias’s classes definition shown above.

So, the next thing is just directly use the class and call it as shown in the following snippet code :

 $data = Input::all();

One thought on “Laravel Error Message : Class ‘App\Http\Controllers\Input’ not found

Leave a Reply