Laravel 8-路由找不到控制器:目标类[Auth \ LoginController]不存在 [英] Laravel 8 - Route cannot find controllers: Target class [Auth\LoginController] does not exist
本文介绍了Laravel 8-路由找不到控制器:目标类[Auth \ LoginController]不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天我去兜风了Laravel 8,但看来Route Facade不再能找到控制器了.
I went to take Laravel 8 for a spin today, but it seems the Route facade cannot find controllers anymore.
路线/home
给我这个错误:
目标类[HomeController]不存在.
Target class [HomeController] does not exist.
运行时出现类似错误: php artisan route:list
I get a similar error when I run: php artisan route:list
Illuminate\Contracts\Container\BindingResolutionException
Target class [Auth\LoginController] does not exist.
at C:\...\vendor\laravel\framework\src\Illuminate\Container\Container.php:811
811 throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
推荐答案
感谢lagbox,我最终在RouteServiceProvider引导方法中向网络路由添加了 namespace('App \ Http \ Controllers')
:
Thanks to lagbox, I ended up adding namespace('App\Http\Controllers')
to the web route in RouteServiceProvider boot method:
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::middleware('web')
->namespace('App\Http\Controllers')
->group(base_path('routes/web.php'));
那对我有用.任何更好的解决方案都将受到欢迎.
That did the trick for me. Any better solutions would be most welcome.
这篇关于Laravel 8-路由找不到控制器:目标类[Auth \ LoginController]不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文