Coder Perfect

class ‘input’ not found in laravel 5

Problem

I have the following lines in my routes.php file:

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 signup form for users. In routes.php, I additionally take the value of the form inputs.

However, when I try to register a user, I get an error. Error:

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

Asked by Gammer

Solution #1

Input, not input, is the correct term. Due to the removal of the Input facade definition from config/app.php, you must manually add it to the aliases array as shown below.

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

Alternatively, you can import Input facade as needed.

use Illuminate\Support\Facades\Input;

Answered by pinkal vansia

Solution #2

For version 5.2 of Laravel:

Add the Input class to aliases in config/app.php:

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

If you’re using Laravel >= 5.2,

Change Request:: to Input::

Answered by Pedro Lobito

Solution #3

In your folderconfigapp.php, you can add a facade.

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

Answered by Nvan

Solution #4

Request:: has replaced Input:: in Laravel 5.2.

use

Request::

Add to the top of any other class, such as Controller.

use Illuminate\Http\Request;

Answered by lewis4u

Solution #5

Your first issue is with the spelling of the input class, which should be Input rather than input. You must also import the class with the appropriate namespace.

use Illuminate\Support\Facades\Input;

If you want it to be called ‘input’ rather than ‘Input,’ add the following:

use Illuminate\Support\Facades\Input as input;

Second, using route.php to store data into the database is a dirty method, and you’re not performing data validation. If a provided argument isn’t what you expected, a SQL error may emerge; the data type is to blame. You should use controller to interact with information and store via the model in the controller method.

The route.php file is responsible for routing. Its purpose is to establish a connection between the controller and the requested route.

http://laravel.com/docs/5.1/ to learn about controllers, middleware, models, and services…

You can join the community at https://laracasts.com/ if you need more information or a solution to a problem.

Regards.

Answered by Disfigure

Post is based on https://stackoverflow.com/questions/31696679/laravel-5-class-input-not-found