简体   繁体   English

类 App\\Http\\Controllers\\WelcomeController 不存在

[英]Class App\Http\Controllers\WelcomeController does not exist

I'm new in Laravel and I can't understand why the controller doesn't work.我是 Laravel 的新手,我不明白为什么控制器不起作用。 Can you help me?你能帮助我吗? Thanks.谢谢。

This is the routes.php file:这是routes.php文件:

routes.php路由文件

This is the WelcomeController controller:这是WelcomeController控制器:

WelcomeController.php欢迎控制器.php

and this is the exception trowed:这是例外:

ReflectionException in Container.php line 737: Container.php 第 737 行中的 ReflectionException:

Class App\\Http\\Controllers\\WelcomeController does not exist类 App\\Http\\Controllers\\WelcomeController 不存在

If you are using the laravel 8 then you can use the below-mentioned code in your web.php route file如果您使用的是 laravel 8,那么您可以在 web.php 路由文件中使用下面提到的代码

use App\Http\Controllers\WelcomeController;

Route::get('/', [WelcomeController::class, 'index'])->name('welcome');

For more information use the laravel 8 documentation https://laravel.com/docs/8.x/routing有关更多信息,请使用 laravel 8 文档https://laravel.com/docs/8.x/routing

You need a WelcomeController.php file in directory Controllers , and you have it in Controllers/Auth你需要在Controllers目录中有一个WelcomeController.php文件,并且你在Controllers/Auth有它

I'd suggest to:我建议:

$>php artisan make:controller WelcomeController

if you forget to choose your method:如果您忘记选择方法:

 Route::get('/', 'WelcomeController')->name('welcome');

change it to:将其更改为:

 Route::get('/', [WelcomeController::class, 'index'])->name('welcome');

or或者

 Route::get('/', 'WelcomeController@YOUR_METHOD_NAME')->name('welcome');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM