php laravel 5:找不到“输入”类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31696679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:34:44  来源:igfitidea点击:

laravel 5 : Class 'input' not found

phplaravellaravel-5laravel-5.1laravel-5.2

提问by Gammer

In my routes.phpfile I have :

在我的routes.php文件中,我有:

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.

我有一个用户注册表格。我也在routes.php.

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

但是当我注册用户时出现错误。错误:

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

回答by pinkal vansia

It is Inputand not input. This commitremoved Inputfacade definition from config/app.phphence you have to manually add that in to aliasesarray as below,

它是Input和不是input此提交删除了Input外观定义,config/app.php因此您必须手动将其添加到aliases数组中,如下所示,

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

Or You can import Inputfacade directly as required,

或者您可以Input根据需要直接导入门面,

use Illuminate\Support\Facades\Input;

回答by CONvid19

For laravel <5.2:

对于 Laravel <5.2

Open config/app.phpand add the Inputclass to aliases:

打开config/app.php并将Input类添加到aliases

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


For laravel >=5.2

对于 Laravel >=5.2

Change Input::to Request::

更改Input::Request::

回答by Nvan

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

你可以在你的 folder\config\app.php

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

回答by lewis4u

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

在 Laravel 5.2 Input:: 替换为 Request::

use

Request::

Add to the top of Controller or any other Class

添加到 Controller 或任何其他类的顶部

use Illuminate\Http\Request;

回答by Disfigure

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.

其次,通过 route.php 存储到数据库中是一种肮脏的方式,而且您没有处理数据验证。如果发送的参数不是您所期望的,可能会出现 SQL 错误,这是由数据类型引起的。您应该使用控制器与信息进行交互并通过控制器方法中的模型进行存储。

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

route.php 文件处理路由。它旨在建立控制器和请求路由之间的链接。

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

了解控制器、中间件、模型、服务... http://laravel.com/docs/5.1/

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

如果您需要更多信息,问题的解决方案,您可以加入社区:https: //laracasts.com/

Regards.

问候。

回答by Ferhat KO?ER

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

如果您使用 Laravel 5.2 版,请查看: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');
   }
 }

回答by Chandrakant Ganji

Declaration in config/app.php under aliases:-

在 config/app.php 中的别名下声明:-

'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;

回答by prakash pokhrel

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

'Input' => Illuminate\Support\Facades\Input::class,将其添加到 App.php 中。

回答by Pradeep Sapkota

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();
});

回答by Deepak Kumar

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

在别名下的 config/app.php 中添加它:-

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