The full message usually looks like this:
Illuminate\Contracts\Container\BindingResolutionException
Target class [App\Http\Controllers\HomeController] does not exist.
Laravel’s service container tried to instantiate the class named in the brackets, asked Composer’s autoloader for it, and no file matched. That bracketed name is your best clue: read it character by character before changing anything.
Causes
- Old route syntax: since Laravel 8,
RouteServiceProviderno longer prefixesApp\Http\Controllersautomatically, soRoute::get('/', 'HomeController@index')looks for a class literally calledHomeControllerwith no namespace. - Letter case: Linux treats
HomeController.phpandHomecontroller.phpas different files. The project runs on Windows or macOS and breaks on the server. - Wrong namespace: the file sits in
app/Http/Controllers/Admin/but itsnamespaceline doesn’t includeAdmin. - Stale autoload files: you added or moved a class without regenerating
vendor/composer/autoload_*.php, or uploaded an oldvendorfolder. - Cached routes:
bootstrap/cache/routes-v7.phpstill points to classes you renamed or deleted. - Unregistered middleware:
Target class [role] does not existmeans the middleware alias was never registered. - A hidden earlier crash:
[view]or[config]in the brackets usually means the app failed before those core services loaded.
How to fix it
- Rewrite the route in
routes/web.phpwith class syntax:
use App\Http\Controllers\HomeController;
Route::get('/', [HomeController::class, 'index']);
- Match folder, filename and namespace.
app/Http/Controllers/Admin/UserController.phpmust start with:
namespace App\Http\Controllers\Admin;
class UserController extends Controller
If you only changed the case of a filename on Windows, use git mv so the rename actually reaches the repository and the server.
- Rebuild the autoloader and clear caches over SSH, from the project folder:
composer dump-autoload -o
php artisan optimize:clear
The second command clears the route, config and view caches together. Without SSH, delete routes-v7.php and config.php from bootstrap/cache/, run composer dump-autoload -o locally and upload the whole vendor folder.
- Register the middleware. In Laravel 11 and later this lives in
bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) {
$middleware->alias([
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
]);
})
In older versions, add it to $middlewareAliases (or $routeMiddleware) in app/Http/Kernel.php.
- Read the log at
storage/logs/laravel.logwhen the bracketed name is a core service such asview,configordb. An earlier error, such as a missing.envor a broken config file, is the real cause, and fixing it removes this message.
Prevention
- Always reference controllers as
[Controller::class, 'method']; your editor flags missing classes immediately. - Keep filenames and class names identical, following PSR-4.
- Make deployment repeatable:
composer install --no-dev -o, thenphp artisan optimize, as in the Laravel deployment guide. - Test on Linux before going live when you can.
On ArabyHost
AI/Developer plans include SSH jailed in CageFS, with Composer and PHP 8.1 to 8.3, so you can run the composer and artisan commands above directly. You can also deploy from GitHub through cPanel Git Version Control and a .cpanel.yml file that runs the same build steps on every push; see the Git deployment guide. If the cause isn’t obvious, ask the Araby AI assistant in the panel: it reads your error log and explains the fix. Plan details are on the developers page and Laravel hosting.
FAQ
Why does it work on my machine but fail on the server?
Almost always letter case. Windows and macOS ignore case in filenames by default; Linux doesn't. Make the filename match the class name exactly, then run composer dump-autoload.
Can I bring back the old 'HomeController@index' syntax?
In Laravel 8 to 10 you can restore the namespace property in RouteServiceProvider. It's better to switch to [HomeController::class, 'index'], which is clearer and lets your editor catch mistakes early.
What does Target class [view] does not exist mean?
The app crashed before the view service was registered, so the real problem is elsewhere. Open storage/logs/laravel.log and look for the first error; it's often a missing .env file or a mistake in a config file.