2
votes

I'm new in Laravel and I can't understand why the controller doesn't work. Can you help me? Thanks.

This is the routes.php file:

routes.php

This is the WelcomeController controller:

WelcomeController.php

and this is the exception trowed:

ReflectionException in Container.php line 737:

Class App\Http\Controllers\WelcomeController does not exist

3

3 Answers

3
votes

If you are using the laravel 8 then you can use the below-mentioned code in your web.php route file

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

2
votes

You need a WelcomeController.php file in directory Controllers, and you have it in Controllers/Auth

I'd suggest to:

$>php artisan make:controller WelcomeController
0
votes

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');