I'm trying to call the Illuminate\Http\Request has method from one of my controllers.

Request::has('fields')

与文档完全一致,但我却抛出了一个错误:

Non-static method Illuminate\Http\Request::has() should not be called statically, assuming $this from incompatible context

我不确定我在这里做错了什么,我试着尽可能地遵循文档.

推荐答案

问题是你使用了错误的Request类.您需要导入外观:

use Illuminate\Support\Facades\Request;

Laravel相关问答推荐

为什么Laravel在API请求时返回BadMethodCallException?

Livewire 3软件包开发

laravel vue 惯性分页器删除上一个和下一个链接

V-icon 在 Vuetify 3 中不显示图标

向 Laravel 模型查询添加计算字段

.gitignore 不忽略文件夹

如何使用 Eloquent Laravel 更新集合

Laravel 5.4 LengthAwarePaginator

Laravel 中的合同和 PHP 中的接口有什么区别?

Laravel 生产问题 - 使用 Laravel 4.1.x 更新composer

不支持驱动Driver[] - Laravel 5.3

如何在 Laravel 5.5 中为选定的请求类设置自定义响应

Eloquent ORM,deleted_at 使用软删除时没有索引

如何在 Laravel 5.1 中改变环境?

Laravel 5.4 有时验证规则不起作用

Laravel:自定义或扩展通知 - 数据库模型

Composer RuntimeException - 无法加载软件包 mews/purifier

如何使 Laravel (Blade) 文本字段只读

Laravel 5.2 验证错误未出现在Blade中

有没有办法让表名自动添加到 Eloquent 查询方法中?