laravel HomeController.php 第 8 行中的 FatalErrorException: Class 'App\Http\Controllers\Controller' not found

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31363631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:55:47  来源:igfitidea点击:

FatalErrorException in HomeController.php line 8: Class 'App\Http\Controllers\Controller' not found

phplaravelauthenticationlaravel-5

提问by ServerSideSkittles

New to laravel and I am trying to setup the user auth. I am using laravel 5.1 so I had to add

Laravel 新手,我正在尝试设置用户身份验证。我正在使用 laravel 5.1 所以我不得不添加

"bestmomo/scafold": "dev-master"

to composer.json

到 composer.json

also in my composer.json

也在我的 composer.json 中

  "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "TestApp\": "app/"
        }
    },

This lets me bring up the register and login pages at /auth/login , /auth/register.

这让我可以在 /auth/login 和 /auth/register 中调出注册和登录页面。

When I complete register it throws back

当我完成注册时,它会退回

FatalErrorException in HomeController.php line 8:
Class 'App\Http\Controllers\Controller' not found

in HomeController.php line 8

I have also named my app using

我还使用命名我的应用程序

php artisan app:name TestApp

The user details are stored correctly in the db, then when I navigate anywhere on the site it throws the error because im assuming its recognised the session.

用户详细信息正确存储在数据库中,然后当我在站点上的任何地方导航时,它都会抛出错误,因为我假设它已识别会话。

I haven't strayed far from guides and this is a simple setup, not sure why its not working.

我没有远离指南,这是一个简单的设置,不知道为什么它不起作用。

I am not sure where the "HomeController" is but the default controller in my dir is Controller.php and contains

我不确定“HomeController”在哪里,但我目录中的默认控制器是 Controller.php 并且包含

namespace TestApp\Http\Controllers;

use TestApp\Http\Controllers\Controller;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

abstract class Controller extends BaseController
{
    use DispatchesJobs, ValidatesRequests;
}

The Dir structure is as follows

目录结构如下

Dir structure

目录结构

回答by Nehal Hasnayeen

When you change your app name your application namespace is also changed , so your application namespace is right now TestApp. so in your HomeController file change your use statement , its still using previous namespace , you should use

当您更改应用程序名称时,您的应用程序名称空间也会更改,因此您的应用程序名称空间现在是 TestApp。所以在你的 HomeController 文件中改变你的 use 语句,它仍然使用以前的命名空间,你应该使用

use TestApp\Http\Controllers\Controller;