Reputation: 2126
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 :
Upvotes: 4
Views: 46581
Reputation: 21
Update the path to your route by adding .
Route::get('/home', [\App\Http\Controllers\HomeController::class, 'index'])->name('home');
Upvotes: 0
Reputation: 123
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
Upvotes: 4
Reputation: 40
For HomeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function welcome()
{
return view('welcome');
}
}
For web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
Route::get('/', [HomeController::class, 'welcome']);
Its work for me
Upvotes: 2
Reputation: 41
You are trying Laravel 7.x and before routing schema. Refer to 8.x documentation.
New syntaxis using as [HomeController::class, 'index']
or you need to add namespace before Controller
name like App\Http\Controllers\HomeController
.
Upvotes: 0
Reputation: 167
First, check if you write the name of the controller correctly. If it is, there are 3 methods:
Route::get('/about', 'App\Http\Controllers\homeController@about');
Write all the paths where your controller there is.
Route::get('/about', [HomeController::class, 'about');
//protected $namespace = 'App\\Http\\Controllers';
( You will find it in comment)//
of comment and save.
with this method, you will able to use the name of the controller directly without
writing all the paths.Upvotes: 9
Reputation: 1
Yes. That is right because you are not giving right path to the action in the routes. Either you update core files for path or provide manually in the route. e.g you have
Route::get('about',"homeController@about");
try this route
Route::get('/about', [App\Http\Controllers\homeController::class,'about']);
or you can type route as
Route::get('/about', 'App\Http\Controllers\homeController@about');
furthermore you can check if you have right code in the controller function.
Upvotes: 0
Reputation: 1217
It can happen because of these two causes:
1) Type Error For this check, please check your HomeController file name and the class name in that file. Both should be same with case sensitivity.
HomeController.php
class HomeController extends
2) Laravel Cache Laravel stores file caches with previous configurations. To refresh the cache, do this commands in the command window and then try again
php artisan cache:clear
php artisan view:clear
php artisan optimize
Hope it solved!.
Upvotes: 1
Reputation: 21
Please update your route
use App\Http\Controllers\HomeController;
Route::get('/about', [HomeController::class, 'about']);
Upvotes: -1
Reputation: 738
I faced a similar issue with the Home controller, in my case I saw the route was configured as following:
Route::get('/home',"homeController@index");
when I changed the above code to the following then it worked.
Route::get('/home',"App\Http\Controllers\HomeController@about");
In your case first, check the spelling first, whether it should be HomeController or homeController.
You can change your route code to the following
so you can try to change the following code
Route::get('about',"HomeController@about");
to
Route::get('about', 'App\Http\Controllers\HomeController@about');
or
Route::get('/about', 'App\Http\Controllers\HomeController@about');
Hope this will work.
Upvotes: 1
Reputation: 44
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller as BaseController;
class homeController extends BaseController{
public function about(){
return view::make('about');
}
}
Should works perfectly. Are you sure that name of file is homeController.php
?
Upvotes: 1
Reputation: 2018
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller as BaseController;
class homeController extends BaseController{
public function about(){
return view::make('about');
}
}
Upvotes: 1