3

我在制作控制器时正在使用 laravel 5.3.29,但出现错误。

运行项目时出错

我到处搜索并且已经尝试过这种方法。

  • 作曲家更新
  • 作曲家转储自动加载

我的路线文件是。 在此处输入图像描述

我的 AuthController 文件。 在此处输入图像描述

如果有人知道我在哪里做错了,请告诉我谢谢。

Laravel.log:

[2017-01-15 07:30:32] local.ERROR: ReflectionException: Class App\Http\Controllers\Auth\AuthController does not exist in C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Container\Con tainer.php:749 Stack trace: #0 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Container\Container.php(749): ReflectionClass->__construct('App\\Http\\Contro...') #1 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Container\Container.php(644): Illuminate\Container\Container->build('App\\Http\\Contro...', Array) #2 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(709): Illuminate\Container\Container->make('App\\Http\\Contro...', Array) #3 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Route.php(203): Illuminate\Foundation\Application->make('App\\Http\\Contro...') #4 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Route.php(316): Illuminate\Routing\Route->getController() #5 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Route.php(278): Illuminate\Routing\Route->controllerMiddleware() #6 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Router.php(666): Illuminate\Routing\Route->gatherMiddleware() #7 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Router.php(646): Illuminate\Routing\Router->gatherRouteMiddleware(Object(Illuminate\Routing\Route)) #8 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Router.php(629): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request)) #9 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Router.php(607): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) #10 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(268): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) #11 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request)) #12 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #13 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(137): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) #14 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #15 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #16 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(150): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #17 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(117): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) #18 C:\laragon\www\MainProject\public\index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) #19 {main}
[2017-01-15 07:30:32] local.ERROR: ReflectionException: Class App\Http\Controllers\Auth\AuthController does not exist in C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Container\Container.php:749 Stack trace: #0 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Container\Container.php(749): ReflectionClass->__construct('App\\Http\\Contro...') #1 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Container\Container.php(644): Illuminate\Container\Container->build('App\\Http\\Contro...', Array) #2 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(709): Illuminate\Container\Container->make('App\\Http\\Contro...', Array) #3 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Route.php(203): Illuminate\Foundation\Application->make('App\\Http\\Contro...') #4 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Route.php(316): Illuminate\Routing\Route->getController() #5 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Route.php(278): Illuminate\Routing\Route->controllerMiddleware() #6 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Routing\Router.php(666): Illuminate\Routing\Route->gatherMiddleware() #7 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(193): Illuminate\Routing\Router->gatherRouteMiddleware(Object(Illuminate\Routing\Route)) #8 C:\laragon\www\MainProject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(163): Illuminate\Foundation\Http\Kernel->gatherRouteMiddleware(Object(Illuminate\Http\Request)) #9 C:\laragon\www\MainProject\public\index.php(58): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\Response)) #10 {main}

4

6 回答 6

3

web.php 中缺少 Auth 文件夹名称,因此它将是

Auth\AuthController@getLogin

我在使用上述语法时在 laravel 8 中遇到了问题,所以请在 web.php 或 api.php 中使用类似的东西 -

使用 App\Http\Controllers\Auth\AuthController

Route::post('login', [AuthController::class, 'getLogin']);
于 2021-10-28T07:08:49.467 回答
1

在 Laravel 4.2 中,我认为你不需要

namespace App\Http\Controllers\Auth
use App\Http\Controllers\Controller

只需将其删除,请注意您的控制器路径

确保您AuthController.php位于app/controllers

你确定你使用的是 Laravel 4.2 吗?为什么路线在web.php

据我所知,如果您使用该结构,您使用的是 Laravel 5.3,请再次确保您使用的是哪个 Laravel 版本

于 2017-01-15T05:01:37.447 回答
1

将路线更改为:

Route::get('/login', 'Auth\AuthController@getLogin');

还要确保类文件在这个目录中:

app\Http\Controllers\Auth
于 2017-01-15T05:14:45.413 回答
1

由于Controller中的手动输入文件而发生的问题。

  • 我删除了我在 sublime 中使用新文件选项创建的手动文件
  • 并使用 laragon 终端 php artisan make:controller
    AuthController 再次添加。
  • 并复制粘贴 previos 代码现在它工作顺利。
于 2017-01-15T13:39:40.153 回答
1

由于未识别命名空间路径。

Route::group([

'middleware' => 'api',
'namespace' => 'App\Http\Controllers',
'prefix' => 'auth'

], function ($router) {

Route::post('login', 'AuthController@login');
Route::post('logout', 'AuthController@logout');
Route::post('refresh', 'AuthController@refresh');
Route::post('me', 'AuthController@me');

});
于 2021-07-16T07:30:03.760 回答
0

将命名空间更改App\Http\ControllersApp\Http\Controllers\Auth

或者,在您的 routes.php 中说Route::get('/login', 'Auth\AuthController@getLogin');

于 2017-01-15T11:07:27.893 回答