[英]Laravel php artisan "Class request does not exist"
I'm working with Laravel,我正在与 Laravel 合作,
suddenly when I try to run php artisan serve
in my command prompt,突然,当我尝试在命令提示符下运行
php artisan serve
时,
it's displaying the error message:它显示错误消息:
In Container.php line 729: Class request does not exist
I have looked in all my controllers, models, and other files I could think of for loose Request references, but found nothing.我查看了我所有的控制器、模型和其他我能想到的松散请求引用文件,但一无所获。
How do I debug this?我该如何调试?
I was having this problem because a config file was calling the request
helper function.我遇到这个问题是因为配置文件正在调用
request
助手 function。
Since I did not use this configuration when running my application from console, I just checked if the request was running from console before using the request
helper.因为我在从控制台运行我的应用程序时没有使用这个配置,所以我只是在使用
request
助手之前检查请求是否从控制台运行。 For example,例如,
# my config file
return [
'conf_key' => (app()->runningInConsole() === false) ? request()?->headers?->get('origin') : null,
// ...
Recheck your Controller class exists, because this error is thrown when there is some difference in Controller class name like重新检查您的控制器类是否存在,因为当控制器类名称存在一些差异时会引发此错误,例如
class PostController extends Controller { }
and和
class Postcontroller extends Controller { }
Notice small "C"注意小“C”
In my case it was a problem with permission to bootstrap/cache
on CI server.在我的情况下,在 CI 服务器上
bootstrap/cache
权限有问题。 Check this directory twice.检查此目录两次。
我在 bootstrap 目录中创建了一个缓存目录,我的问题解决了
I was using request()
in config.php
, and I don't know why this works until some day that crash with this error.我在
config.php
中使用request()
,我不知道为什么会这样,直到有一天因为这个错误而崩溃。 The site was working well, but composer/artisan commands fail.该站点运行良好,但 composer/artisan 命令失败。 I think it's normal, because there is no request... I handled checking
isset($_SERVER["SERVER_NAME"])
, because I need the SERVER_NAME
to config some parameters.我认为这是正常的,因为没有请求...我处理了检查
isset($_SERVER["SERVER_NAME"])
,因为我需要SERVER_NAME
来配置一些参数。
I struggled with this issue for a while.我在这个问题上挣扎了一段时间。
Turns out, my issue was in a config file.原来,我的问题出在配置文件中。 One of my config classes was calling a static method with a bug in it.
我的一个配置类调用了一个带有错误的静态方法。
The way I found it was to add echo statements in the following 2 files:我发现它的方法是在以下 2 个文件中添加 echo 语句:
vendor\/laravel\/framework\/src\/Illuminate\/Container.php<\/code>
To echo the classes the container is building.呼应容器正在构建的类。
/**
* Instantiate a concrete instance of the given type.
*
* @param string $concrete
* @return mixed
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function build($concrete)
{
// If the concrete type is actually a Closure, we will just execute it and
// hand back the results of the functions, which allows functions to be
// used as resolvers for more fine-tuned resolution of these objects.
if ($concrete instanceof Closure) {
return $concrete($this, $this->getLastParameterOverride());
}
echo 'Build - ' . $concrete . PHP_EOL;
$reflector = new ReflectionClass($concrete);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.