类 App\Http\Controllers\AuthController 不存在 Laravel 5.2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36149442/
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 13:27:33  来源:igfitidea点击:

Class App\Http\Controllers\AuthController does not exist Laravel 5.2

phplaravellaravel-5laravel-5.1laravel-5.2

提问by Awn Ali

My whole application, made in Laravel 5.2, is working perfectly fine but when i tried to get list of routes through following command:

我在 Laravel 5.2 中制作的整个应用程序运行良好,但是当我尝试通过以下命令获取路由列表时:

php artisan route:list

php工匠路线:列表

It shows me following error:

它向我显示以下错误:

[ReflectionException] Class App\Http\Controllers\AuthController does not exist

[ReflectionException] 类 App\Http\Controllers\AuthController 不存在

i tried to add namespace aswell:

我也尝试添加命名空间:

Route::group(['middleware' => ['web'], 'namespace' => 'Auth'], function () {
    Route::auth();
});

then it shows me following error:

然后它向我显示以下错误:

[ReflectionException]
Class App\Http\Controllers\Auth\Auth\AuthController does not exist

[ReflectionException]
类 App\Http\Controllers\Auth\Auth\AuthController 不存在

My routes file is:

我的路线文件是:

Route::group(['middleware' => ['web'], 'namespace'=>'Auth'], function() {
     Route::auth(); 
});

Update: content of Router.php

更新:Router.php 的内容

public function auth()
{
    // Authentication Routes...
    $this->get('login', 'Auth\AuthController@showLoginForm');
    $this->post('login', 'Auth\AuthController@login');
    $this->get('logout', 'Auth\AuthController@logout');

    // Registration Routes...
    $this->get('register', 'Auth\AuthController@showRegistrationForm');
    $this->post('register', 'Auth\AuthController@register');

    // Password Reset Routes...
    $this->get('password/reset/{token?}', 'Auth\PasswordController@showResetForm');
    $this->post('password/email', 'Auth\PasswordController@sendResetLinkEmail');
    $this->post('password/reset', 'Auth\PasswordController@reset');
}

Please help! Thanks

请帮忙!谢谢

回答by Skel

I cannot comment so I'm going to ask have you run php artisan make:authand with laravel 5.2 you dont need your routes in your Routes.php. All you have to have in your href="{{ url('/login') }}"

我无法发表评论,所以我会问你有没有跑步,php artisan make:auth并且在 Laravel 5.2 中你不需要你的路线在你的Routes.php. 所有你必须拥有的href="{{ url('/login') }}"

回答by saber tabatabaee yazdi

in my case just remove:

就我而言,只需删除:

     'namespace' => 'App\Http\Controllers',

namespace =>App\Http\Controllers

命名空间 =>App\Http\Controllers

回答by Imran Qamer

I had similar problems using voyager package, but this command worked for me and everything is working now.

我在使用 voyager 包时遇到了类似的问题,但这个命令对我有用,现在一切正常。

php artisan config:cache

回答by Martian.titan

I got the same issue and I found out what was the issue. My code was look like this:

我遇到了同样的问题,我发现了问题所在。我的代码是这样的:

namespace App\Http\Controllers\Auth;
namespace App\Repositories;

And I changed to this:

我改成这样:

namespace App\Repositories;
namespace App\Http\Controllers\Auth;

Issue solved for me.

问题为我解决。

回答by Mahfuz Shishir

I got the same problem. Just use

我遇到了同样的问题。只需使用

Route::get('/login',[
    'uses' => 'Auth\AuthController@login',
    'as'   => 'login'
]);

回答by orestiss

In laravel 5.2 you can use php artisan make:auth, this creates a line

在 Laravel 5.2 中你可以使用php artisan make:auth,这会创建一条线

Route::auth()in your routes.phpfile. And creates all the necessary

Route::auth()在您的routes.php文件中。并创建所有必要的

routes.

路线。

Also your namespacing solution would probably work if you remove the Authpart from

如果您Auth

'Auth\AuthController@showRegistrationForm'

'Auth\AuthController@showRegistrationForm'

and leave it like

然后让它像

'AuthController@showRegistrationForm'.

'AuthController@showRegistrationForm'.