Laravel 5 Illuminate \ Http \ Request有不允许静态调用的方法

[英]Laravel 5 Illuminate\Http\Request has method not allowing static call


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

我正试图从我的一个控制器调用Illuminate \ Http \ Request has方法。

Request::has('fields')

Following from the documentation exactly, yet I'm getting an error thrown:

从文档中准确地说,但是我收到了一个错误:

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

非静态方法Illuminate \ Http \ Request :: has()不应该静态调用,假设$ this来自不兼容的上下文

I'm not sure what I'm doing wrong here, I tried following the documentation as closely as possible.

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

3 个解决方案

#1


46  

The problem is you are using the wrong Request class. You need to import the Facade:

问题是你使用了错误的Request类。您需要导入Facade:

use Illuminate\Support\Facades\Request;

#2


3  

The use Illuminate\Support\Facades\Request; is using the Facade which is not good practice. should use Illuminate\Http\Request; and get the request available via the method or constructor ie.-

使用Illuminate \ Support \ Facades \ Request;使用Facade这不是一个好习惯。应该使用Illuminate \ Http \ Request;并通过方法或构造函数获取请求ie--

public function __construct(Request $request) {
    $this->request = $request;
}

and then in the method use it, ie.

然后在方法中使用它,即。

public function checkText() {
   $txt = $this->request->has('txt'); 
   return $txt;
}

#3


0  

Try using Input::has() instead then use Input::get() to actually grab the corresponding POSTED/GET var.

尝试使用Input :: has(),然后使用Input :: get()实际获取相应的POSTED / GET var。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/02/09/ab5c6368c925c936ba8bb69e9dcc98c6.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号