Laravel 6.0 php artisan route:list 返回“目标类 [App\Http\Controllers\SessionsController] 不存在。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/57865517/
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
Laravel 6.0 php artisan route:list returns “Target class [App\Http\Controllers\SessionsController] does not exist.”
提问by Andreas
I am using Laravel 6.0 and I try to list all my routes with artisan route:list
, but it fails and returns:
我正在使用 Laravel 6.0 并尝试使用 列出我的所有路线artisan route:list
,但它失败并返回:
Illuminate\Contracts\Container\BindingResolutionException : Target class [App\Http\Controllers\SessionsController] does not exist.
at /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:806 802| 803| try { 804| $reflector = new ReflectionClass($concrete); 805| } catch (ReflectionException $e) {
806| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e); 807| } 808| 809| // If the type is not instantiable, the developer is attempting to resolve 810| // an abstract type such as an Interface or Abstract Class and there is
Exception trace:
1 Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console{closure}(Object(Illuminate\Routing\Route)) [internal]:0
2 ReflectionException::("Class App\Http\Controllers\SessionsController does not exist") /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:804
3 ReflectionClass::__construct("App\Http\Controllers\SessionsController") /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:804
Illuminate\Contracts\Container\BindingResolutionException:目标类 [App\Http\Controllers\SessionsController] 不存在。
在/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:806 802| 803| 试试 { 804| $reflector = new ReflectionClass($concrete); 805| } catch (ReflectionException $e) {
806| throw new BindingResolutionException("目标类 [$concrete] 不存在。", 0, $e); 807| } 808| 809| // 如果类型不可实例化,则开发人员正在尝试解析 810| // 一个抽象类型,例如接口或抽象类,并且有
异常跟踪:
1 Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console{closure}(Object(Illuminate\Routing\Route)) [内部]:0
2 ReflectionException::("Class App\Http\Controllers\SessionsController 不存在") /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:804
3 ReflectionClass::__construct("App\Http\Controllers\SessionsController") /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:804
Up to now I just have a very simple web.php routes file:
到目前为止,我只有一个非常简单的 web.php 路由文件:
Route::get('/', function () {
return view('index');
});
Route::prefix('app')->group(function () {
// Registration routes
Route::get('registration/create', 'RegistrationController@create')->name('app-registration-form');
});
// Templates
Route::get('templates/ubold/{any}', 'UboldController@index');
Any idea how I could debug this issue?
知道如何调试这个问题吗?
Many thanks in advance!
提前谢谢了!
回答by Boris N
For those who have similar issue with Illuminate\Contracts\Container\BindingResolutionException : Target class [<className>] does not exist.
message, this also could be helpful:
对于那些对Illuminate\Contracts\Container\BindingResolutionException : Target class [<className>] does not exist.
消息有类似问题的人,这也可能会有所帮助:
composer dump-autoload
回答by mukesh kumar
Run this command
运行这个命令
php artisan config:cache
回答by Haritsinh Gohil
In my case same error
occurred because of forward slash /
but it should be backward slash \
in defining route,
在我的情况下,error
由于正斜杠/
而发生同样的情况,但\
在定义路线时应该是反斜杠,
it happens when you have controller in folder
like as in my case controller was in api
Folder, so always use backward slash \
while mentioning controller name.
当你有控制器时会发生这种情况,folder
就像我的控制器在api
文件夹中一样,所以\
在提到控制器名称时总是使用反斜杠。
see example:
见示例:
Error-prone code:
容易出错的代码:
Route::apiResource('categories', 'api/CategoryController');
Solution code:
解决方案代码:
Route::apiResource('categories', 'api\CategoryController');
回答by Vipertecpro
Alright i got similar problem, i was trying to be smart so i wrote this in my web.php
好吧,我遇到了类似的问题,我想变得聪明,所以我在 web.php 中写了这个
Route::group([
'middleware' => '', // Removing this made everything work
'as' => 'admin.',
'prefix' => 'admin',
'namespace' => 'Admin',
],function(){
});
All i had to do is just to remove all the unnecessary/unused option from group. That's all.
我所要做的就是从组中删除所有不必要/未使用的选项。就这样。
回答by Ahmed Abderrahman
try to correct your controller name
尝试更正您的控制器名称
my route was
我的路线是
Route::get('/lien/{id}','liensControler@show');
and my controller was
我的控制器是
class liensController extends Controller
{
// all the methods of controller goes here.
}
回答by aphoe
In my case it was a matter of Linux's file name case sensitivity. For a file named IndexController
, having Indexcontroller
will work in windows but not in Linux
就我而言,这是 Linux 文件名区分大小写的问题。对于名为 的文件IndexController
,Indexcontroller
在 Windows中可以使用,但在 Linux 中不行