Laravel Request::input 调用未定义的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34774468/
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-09-14 13:02:40  来源:igfitidea点击:

Laravel Request::input Call to undefined method

phplaravellaravel-5

提问by Tom1410

I'm new to Laravel framework and now facing with a problem while trying update logged users info.

我是 Laravel 框架的新手,现在在尝试更新登录的用户信息时遇到问题。

Route:

路线:

Route::post('/user/{id}', function (Request $request, $id) {
    return App\Http\Controllers\UsersController::update($request, $id);
});

public static function update($request, $id)
{
    $user = User::find($id);
    $user->name = $request->input('name');
    ...
    $user->save();
    ...
}

Error:

错误:

FatalErrorException in UsersController.php line 24: Call to undefined method Illuminate\Support\Facades\Request::input()

UsersController.php 第 24 行中的 FatalErrorException:调用未定义的方法 Illuminate\Support\Facades\Request::input()

回答by jedrzej.kurylo

Add the following import at the top of your file:

在文件顶部添加以下导入:

use Illuminate\Http\Request;

otherwise your controller gets injected instance of Requestclass from global namespace that is an alias of Illuminate\Support\Facades\Request./

否则你的控制器会从全局命名空间中注入Request类的实例,它是Illuminate\Support\Facades\Request的别名。/