laravel 5 : Class 'input' not found

PhpLaravelLaravel 5Laravel 5.1Laravel 5.2

Php Problem Overview


In my routes.php file I have :

Route::get('/', function () {

    return view('login');
});

Route::get('/index', function(){
    return view('index');
});

Route::get('/register', function(){
    return view('register');
});
Route::post('/register',function(){

    $user = new \App\User;
    $user->username = input::get('username');
    $user->email  = input::get('email');
    $user->password = Hash::make(input::get('username'));
    $user->designation = input::get('designation');
    $user->save();

});

I have a form for users registration. I am also taking the form inputs value in the routes.php.

But the error comes up when I register a user . Error:

FatalErrorException in routes.php line 61:
Class 'input' not found

Php Solutions


Solution 1 - Php

It is Input and not input. This commit removed Input facade definition from config/app.php hence you have to manually add that in to aliases array as below,

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

Or You can import Input facade directly as required,

use Illuminate\Support\Facades\Input;

Solution 2 - Php

For laravel < 5.2:

Open config/app.php and add the Input class to aliases:

'aliases' => [
// ...
  'Input' => Illuminate\Support\Facades\Input::class,
// ...
],

For laravel >= 5.2

Change Input:: to Request::

Solution 3 - Php

You can add a facade in your folder\config\app.php

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

Solution 4 - Php

In Laravel 5.2 Input:: is replaced with Request::

use

Request::

Add to the top of Controller or any other Class

use Illuminate\Http\Request;

Solution 5 - Php

In first your problem is about the spelling of the input class, should be Input instead of input. And you have to import the class with the good namespace.

use Illuminate\Support\Facades\Input;

If you want it called 'input' not 'Input', add this :

use Illuminate\Support\Facades\Input as input;

Second, It's a dirty way to store into the database via route.php, and you're not processing data validation. If a sent parameter isn't what you expected, maybe an SQL error will appear, its caused by the data type. You should use controller to interact with information and store via the model in the controller method.

The route.php file handles routing. It is designed to make the link between the controller and the asked route.

To learn about controller, middleware, model, service ... http://laravel.com/docs/5.1/

If you need some more information, solution about problem you can join the community : https://laracasts.com/

Regards.

Solution 6 - Php

In larvel => 6 Version:

Input no longer exists In larvel 6,7,8 Version. Use Request instead of Input.

Based on the Laravel docs, since version 6.x Input has been removed.

The Input Facade

Likelihood Of Impact: Medium

> The Input facade, which was primarily a duplicate of the Request > facade, has been removed. If you are using the Input::get method, you > should now call the Request::input method. All other calls to the > Input facade may simply be updated to use the Request facade.

use Illuminate\Support\Facades\Request;
..
..
..
 public function functionName(Request $request)
    {
        $searchInput = $request->q;
}

Solution 7 - Php

if You use Laravel version 5.2 Review this: https://laravel.com/docs/5.2/requests#accessing-the-request

use Illuminate\Http\Request;//Access able for All requests
...

class myController extends Controller{
   public function myfunction(Request $request){
     $name = $request->input('username');
   }
 }

Solution 8 - Php

Declaration in config/app.php under aliases:-

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

Or You can import Input facade directly as required,

use Illuminate\Support\Facades\Input;

or

use Illuminate\Support\Facades\Input as input;

Solution 9 - Php

'Input' => Illuminate\Support\Facades\Input::class, add it to App.php.

Solution 10 - Php

This clean code snippet works fine for me:

use Illuminate\Http\Request;
Route::post('/register',function(Request $request){

   $user = new \App\User;
   $user->username = $request->input('username');
   $user->email  = $request->input('email');
   $user->password = Hash::make($request->input('username'));
   $user->designation = $request->input('designation');
   $user->save();
});

Solution 11 - Php

Add this in config/app.php under aliases:-

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

Solution 12 - Php

Miscall of Class it should be Input not input

Solution 13 - Php

It's changed in laravel 6. See for more info here

Don't do anything in app.php and anywhere else, just replace

input::get() with Request::input()

and

on top where you declare Input,Validator,Hash etc., remove Input and add Request

use something like :

Config,DB,File,Hash,Input,Redirect,Session,View,Validator,Request;

Solution 14 - Php

   #config/app.php
   'aliases' => [
        ...
        'Input' => Illuminate\Support\Facades\Input::class,
        ...
    ],

   #Use Controller file
   use Illuminate\Support\Facades\Input;
   ==OR==
   use Input;

Read full example: https://devnote.in/laravel-class-input-not-found

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGammerView Question on Stackoverflow
Solution 1 - Phppinkal vansiaView Answer on Stackoverflow
Solution 2 - PhpPedro LobitoView Answer on Stackoverflow
Solution 3 - PhpNvanView Answer on Stackoverflow
Solution 4 - Phplewis4uView Answer on Stackoverflow
Solution 5 - PhpDisfigureView Answer on Stackoverflow
Solution 6 - PhpHaronView Answer on Stackoverflow
Solution 7 - PhpFerhat KOÇERView Answer on Stackoverflow
Solution 8 - PhpChandrakant GanjiView Answer on Stackoverflow
Solution 9 - Phpprakash pokhrelView Answer on Stackoverflow
Solution 10 - PhpPradeep SapkotaView Answer on Stackoverflow
Solution 11 - PhpDeepak KumarView Answer on Stackoverflow
Solution 12 - PhpKenneth SundayView Answer on Stackoverflow
Solution 13 - PhpGOLDENSPARROW MOBILEView Answer on Stackoverflow
Solution 14 - PhpFefar RaviView Answer on Stackoverflow