Laravel 5: class input not found

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 user registration form. I also accept the value of the form input in routes.php .

But the error occurs when I register a user. Mistake:

 FatalErrorException in routes.php line 61: Class 'input' not found 
+67
php laravel laravel-5
Jul 29 '15 at 9:39 on
source share
9 answers

This is Input , not Input . This commit removed the Input facade definition from config/app.php , so you need to manually add this to the aliases array, as shown below,

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

Or you can directly import the Input facade, if required,

 use Illuminate\Support\Facades\Input; 
+174
Jul 29 '15 at 9:41
source share

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

 'Input' => Illuminate\Support\Facades\Input::class, 
+22
Jan 26 '16 at 20:56 on
source share

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::

+18
May 15 '16 at 21:44
source share

In Laravel 5.2, Input :: is replaced by Request ::

So when you need to enter something instead of using

 Input:: 

use

 Request:: 

And if you get an error, then about "should not be used statically" just add this to the top of the file

 use Request; 

If you already have this line:

 use Illuminate\Http\Request; 

delete it because you cannot have two classes with the same name in the same file

+14
May 13 '16 at 7:11
source share

First of all, your problem is to write the input class, and instead of input, the input. And you need to import a class with a good namespace.

 use Illuminate\Support\Facades\Input; 

If you want it to be called "input" and not "Input", add this:

 use Illuminate\Support\Facades\Input as input; 

Secondly, this is a dirty way to store in the database via route.php, and you are not processing data validation. If the parameter sent does not match what was expected, an SQL error may occur caused by the data type. You must use the controller to interact with the information and store through the model in the controller method.

The route.php file handles routing. It is designed to establish communication between the controller and the requested route.

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

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

Sincerely.

+5
Jul 29 '15 at 9:48
source share

if you are using Laravel 5.2. Check it out: 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'); } } 
+4
Jul 03 '16 at 17:09
source share

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

+2
May 19 '17 at 6:37 a.m.
source share

Add this to config / app.php under the aliases: -

 'Input' => Illuminate\Support\Facades\Input::class, 
0
Dec 06 '17 at 9:53 on
source share

Unlike a function, it must be "Input not" input

0
Dec 07 '17 at 1:12
source share



All Articles