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

EliasNiyonsaba's avatar

Target class [CarrierController] does not exist.

Illuminate\Contracts\Container\BindingResolutionException Target class [CarrierController] does not exist.

I have a navigation with a mega menu with this link http://localhost:8000/about-us/carrier

how can I make it dynamic the router? Can anyone help me to know the codes of route? and controller?

0 likes
6 replies
Neeraj1005's avatar
Level 9

@eliasniyonsaba If you are using Laravel8 do this.

To App/Providers/RouteServiceProvider.php add $namespace

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';
}

and this

/**
 * Define your route model bindings, pattern filters, etc.
 *
 * @return void
 */
public function boot()
{
    $this->configureRateLimiting();

    $this->routes(function () {
        Route::middleware('web')
            ->namespace($this->namespace) // add this line
            ->group(base_path('routes/web.php'));

        Route::prefix('api')
            ->middleware('api')
            ->namespace($this->namespace) // and this line
            ->group(base_path('routes/api.php'));
    });
}
2 likes
onabright's avatar

@eliasniyonsaba It could be an issue with the name space inside your routes/web.php file. Make sure the controller is properly referenced like: use App\Http\Controllers\CarrierController;

josh__gikundiro's avatar

I am facing the same problem. I had been accessing my routes well till I received the error stating "Target class [Controller] does not exist." I am using laravel 10.18.0 this is my Controller

I can't even return any view.... May somebody help please ??

Please or to participate in this conversation.