欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

laravel 5 : Class 'input' not found input 有大用


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
shareimprove this questionedited Jun 29 '16 at 5:25alariva7481828asked Jul 29 '15 at 9:39Gammer1,46941847
 

7 Answers 正确答案

up vote165down voteaccepted

It is Input and not inputThis commit removed Input facade definition from config/app.phphence 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;
shareimprove this answeredited Apr 29 '16 at 8:08Ash5,2001652100answered Jul 29 '15 at 9:41pinkal vansia6,18343051
 
   What if I use laravelcollective for the forms in laravel 5.2 and I use {{ Form }} in a view, not in routes as Shafee does. {{ Form::text('name', Input::old('name'), array('class' => 'form-control')) }} – nclsvh Dec 27 '15 at 12:252 You can use \Input to access it globally – pinkal vansia Dec 27 '15 at 12:39   How or where do I need to put this? Changing Input to \Input (inside the form tags) does not work.. Also I am not using illuminate\support\facades.. but "laravelcollective/html": "5.2.*" – nclsvh Dec 27 '15 at 13:48   Sorry I did not pay attention to your earlier comment but in HTML you can use helper function old() which is nothing but wrapper for Input::old() – pinkal vansia Dec 27 '15 at 15:47   @NicolasV you can put it under aliases inside config/app.php, as Nvan's answer points out. – Nik Sumeiko Jan 31 '16 at 21:25

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

'Input' => Illuminate\Support\Facades\Input::class,
shareimprove this answeredited Feb 19 '16 at 13:37  answered Jan 26 '16 at 20:56Nvan824721
 

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

shareimprove this answeredited Oct 13 '16 at 3:25  answered May 15 '16 at 21:44Pedro Lobito37.6k1089132
 

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

So where ever you need to input something instead of using

Input::

use

Request::

And if you get error something about 'should not use statically' just add this at the top of your file

use Request;

If you already have this line:

use Illuminate\Http\Request;

delete it because you can't have two classes with the same name in one file

shareimprove this answeredited May 13 '16 at 9:04  answered May 13 '16 at 7:11lewis4u2,56111932
 

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.

shareimprove this answeredited Jul 29 '15 at 9:55  answered Jul 29 '15 at 9:48Disfigure334213
 

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');
   }
 }
shareimprove this answeranswered Jul 3 '16 at 17:09Ferhat KOÇER1,030810
 

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

shareimprove this answeredited Sep 11 at 20:17Gammer1,46941847answered May 19 at 6:37prakash pokhrel55114
 

来自 https://stackoverflow.com/questions/31696679/laravel-5-class-input-not-found

  •  

  •  

  •  

  •  

  •  

  •  

  •  

  •  

  •  

  •  

  •  

  •  

  •  

  •  

  •  


普通分类: