1
votes

My controller is not working when i am attaching router and controller with each other. It is showing the error

Class App\Http\Controllers\HelloController does not exist.

I hope my syntax and everything is right but can't figure out the issue.

Filename is also same as class name.

namespace I used is :

namespace App\Http\Controllers\;

Route code:

Route::get('sayHello', 'HelloController@index');

Controller Code:

class HelloController extends Controller
{
    public function index()
    {
        return view('hello');
    }
}
1
Double check for spelling mistake.zahid hasan emon
Hi, You can checked by running command compuser dump-autoloadGohel Dhaval
@DhavalGohel please tell me what can i check with this command ?Haseeb Attique
@HaseebAttique Are you run this command in terminal? i think it cache issue in laravel.Gohel Dhaval
Yes i run in terminal.Haseeb Attique

1 Answers

1
votes

The namespace for the controller should be:

namespace App\Http\Controllers; 

Notice it doesn't have "\" at the end.

Once you have changed the above it will be worth running:

composer dumpautoload

When creating a controller in the future it will probably be worth using the artisan command make:controller:

php artisan make:controller SomeNewController

The issue is the <? php at the top of your controller class. It should be <?php (no space)