Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shewi's avatar
Level 2

Target class controller does not exist

Hi everyone ,

I'm new to laravel & I totally enjoy it . I recently joined a project (project is base on laravel 6) , the project works totally fine on my coworkers computers, my problem is that when i clone it and launch it , i get a :

Illuminate \ Contracts \ Container \ BindingResolutionException
Target class [App\Http\Controllers\SiteWeb] does not exist.

exemple of a route :

Route::get('', 'SiteWeb@index')->name('welcome');

The controller itself is in a folder :

App/Controllers/Api/Website

Namespace in the controller seems ok :

namespace App\Http\Controllers;

I tried without effect:

composer dump-autoload 
php artisan config:cache
php artisan cache:clear
....

I had a look through many post / discussion but i can't find any appropriate solution, Any help would be really appreciated :) Thanks in advance !

0 likes
9 replies
tykus's avatar

The namespace should map to the directory if the project is using PSR-4 autoloading.

So, App\Http\Controllers\SiteWeb class would be located in app/Http/Controllers directory.

Shewi's avatar
Level 2

if i understand what you say the namespace should always be app/Http/Controllers , even if the controller is in a subfolder here for exemple App/Controllers/Api/Website/SiteWeb.php.

But the problem in my case is that in the controller SiteWeb.php , the namespace is

namespace App\Http\Controllers;

I also checked RouteServiceProvide.php and this is written :

    protected $namespace = 'App\Http\Controllers';

About ps-4 autoloading (even though i dont relly know the use of it), i can see a line about it in composer.json

        "psr-4": {
            "App\": "app/"
        },

Thanks for your time !!! :)

tykus's avatar

if the Controller is in that directory, then the namespace should be

App\Controllers\Api\Website

And your route definition will need to be absolute, rather than relative (not 100% sure if this will work when there is a namespace defined in the RouteServiceProvider):

Route::get('', '\App\Controllers\Api\Website\SiteWeb@index')->name('welcome');
vincent15000's avatar

In your web.php (route) file, you have to declare the class.

use App\Http\Controllers\SiteWeb;

And to declare the route, with Laravel 8 you have a new syntax.

Route::get('', [SiteWeb::class, 'index'])->name('welcome');

Oh sorry ... I have just seen you are using Laravel 6.

So you can write this ;).

Route::get('', 'SiteWeb@index')->name('welcome');

Tell me if it helps ;).

Shewi's avatar
Level 2

Didnt worked , but thanks anyway :)

double-a's avatar

as @tykus mentioned you namespace is not mapping the directory tree,

change the controller's namspace to

namespace App\Http\Controllers\Api\Website;

and the route should looks like this

Route::get('', 'Api\Website\SiteWeb@index')->name('welcome');
Shewi's avatar
Level 2

Ho , I understood it wrong the first time , but even if i change the namespace to

namespace App\Http\Controllers\Api\Website;

I still have the target class error ...

The weird part is that for my coworker everything s fine when they clone the project, and they have the same cloned repo as I do... I'm really confused about that...

vincent15000's avatar

Perhaps you should have a look at the RouteServiceProvider.php file.

/**
 * The controller namespace for the application.
 *
 * When present, controller route declarations will automatically be prefixed with this namespace.
 *
 * @var string|null
 */
protected $namespace = 'App\Http\Controllers';

If a namespace is specified in the provider, you don't have to specify it in the web.php file.

Shewi's avatar
Shewi
OP
Best Answer
Level 2

I've found the issue ,

it was the version of composer which made the error, i was on 2.* and i downgraded to 1.6* , which is i think, the one use for the original project.

Please or to participate in this conversation.