Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class App\Http\Controllers\homeController does not exist [duplicate]

Tags:

php

laravel

i'm using laravel 5 , in rutes.php i have this code :

Route::get('about',"homeController@about");

and in App\Http\Controllers\ i have file homeController.php that contains :

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller as BaseController;

class homeController extends BaseController{
public function about(){
    return view::make('about');
}
}

but it throws this error : Class App\Http\Controllers\homeController does not exist . how can i fix it ?

here is structure of the project and controllers : enter image description here

like image 847
ako Avatar asked Oct 29 '25 14:10

ako


2 Answers

First, check if you write the name of the controller correctly. If it is, there are 3 methods:

  1. Route::get('/about', 'App\Http\Controllers\homeController@about'); Write all the paths where your controller there is.

  2. Route::get('/about', [HomeController::class, 'about');

    • Go to file RouteServiceProvider.php in Providers folder
    • Search for //protected $namespace = 'App\\Http\\Controllers'; ( You will find it in comment)
    • Remove // of comment and save. with this method, you will able to use the name of the controller directly without writing all the paths.
like image 185
Boulanfad Mustapha Avatar answered Nov 01 '25 05:11

Boulanfad Mustapha


change your routing like below:

use App\Http\Controllers\HomeController;

Route::get('/about',  [HomeController::class, 'index'])->name('home');

for more info look at this page: https://laravel.com/docs/8.x/routing

like image 29
milad Avatar answered Nov 01 '25 04:11

milad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!