Class AppHttpControllersPostController does not exist(类 AppHttpControllersPostController 不存在)
问题描述
让我先说我知道这个问题经常被问到."当我说没有任何效果时,请相信我.
Let me just start by saying "I know this question gets asked a lot." believe me when i say nothing has worked for me.
我创建了一个名为 PostController
的控制器.这是我博客的控制器.当我导航到我的博客时,我收到以下错误 Class AppHttpControllersPostController does not exist
即使它确实存在.控制器名为 PostController.php
.下面是路由的样子 Route::get('blog','PostController@index');
.我读到运行一些 composer
命令会有所帮助,但没有一个对我有帮助.composer dumpautoload
以及 composer update
.我在这里错过了一些步骤吗?有人遇到过类似的问题吗?如果需要其他信息,请告诉我.
I have created a controller called PostController
. This is a controller for my blog. When I navigate to my blog i get the following error Class AppHttpControllersPostController does not exist
even though it does exist. The controller is called PostController.php
. Here is what the route looks like Route::get('blog','PostController@index');
. I have read that running some composer
commands will help but none of them have helped me. composer dumpautoload
as well as composer update
. Am i missing some step here? Anyone run into a similar problem? Please let me know if additional information is needed.
编辑这是顶部的命名空间.
这是整个控制器.
谢谢.
推荐答案
如果 composer dumpautoload
没有帮助,请检查 PostController 中是否有正确的
并仔细检查类名/路由声明中的拼写错误.namespace
声明.php
If composer dumpautoload
is not helping then check if you have proper namespace
declaration in PostController.php
and double check for typos in class name/route declaration.
如果失败,请检查 composer.json
的自动加载配置,它应该是这样的:
If this fails check composer.json
for autoload configuration, it should have something like this:
作为旁注,您可以使用以下内容:
As a side note you could use something like this:
或
有了这个,任何体面的 IDE 都应该在找不到文件/有拼写错误时发出某种警告
With this any decent IDE should give some kind of a warning if it can't find the file/there's a typo
编辑:
你的文件应该有这样一行
Your file should have a line like this
在文件的开头,在 <?php
或 <?php declare(strict_types = 1);
之后,如果您使用的是 php7 严格模式
At the beggining of the file, right after <?php
or <?php declare(strict_types = 1);
if you're using php7 strict mode
这篇关于类 AppHttpControllersPostController 不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!