Home > Enterprise >  laravel Target class [TestController] does not exist
laravel Target class [TestController] does not exist

Time:09-28

I use Laravel Framework 9.31.0 on win11

I already tried everything but nothing helped.

I used action syntax in the file routes\web.php:

Route::get('role', [TestController::class, 'index']);

or full path to controller:

=> 'app\Http\Controllers\TestController@index'

or like this:

use app\Http\Controllers\TestController;

Also I declared variable $namespace in the file app\Providers\RouteServiceProvider.php and told laravel to use that for our web and api routes:

class RouteServiceProvider extends ServiceProvider
{
    public const HOME = '/home';
    protected $namespace = 'app\\Http\\Controllers';

    public function boot()
    {
        $this->configureRateLimiting();

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

            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));
        });
    }

Nobody helps. What am I doing wrong?

CodePudding user response:

Try this

use App\Http\Controllers\TestController;

respect characters

  • Related