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

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

错误:

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

推荐答案

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

use Illuminate\Http\Request;

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

Laravel相关问答推荐

无法在终端cPanel中打开输入文件:artisan

如何在 Laravel 中使用多对一变形关系

Laravel AppServiceProvider 中的代码在通过 DeployHQ 部署时停止 Composer 和构建

Laravel Eloquent 查找日期超过 2 天的行

Laravel:在失败时处理 findOrFail()

"public/index.php" 可以在 laravel 中按组写入

Laravel 中的 index()" 是什么意思?

路由中间的可选参数

如何使用 Eloquent Laravel 更新集合

Laravel Eloquent:访问属性和动态表名

如何仅从 laravel FormRequest 中获取经过验证的数据?

如何在 Laravel 中创建类别的嵌套列表?

如何在 Laravel 5.2 中手动发送密码重置请求?

如何在 Laravel 5 中验证当前、新密码和新密码确认?

Laravel 控制器构造

干预图像:直接从带有原始文件名和分机的网址保存图像?

如何在 Laravel 5.2 中使用 OR 条件将多个参数传递给中间件

今天之前的 Laravel 规则......怎么办

Laravel X-CSRF-Token 与 POSTMAN 不匹配

Laravel Eloquent 多对多查询 whereIn