skip to Main Content

I use Laravel Framework 9.31.0 on win11

I used action syntax in the file routesweb.php:

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

or full path to controller:

=> 'appHttpControllersTestController@index'

or like this:

use appHttpControllersTestController;

Also I declared variable $namespace in the file appProvidersRouteServiceProvider.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'));
        });
    }

Nothing helps. What am I doing wrong?

3

Answers


  1. Export the TestController Path using his correct namespace.

    Login or Signup to reply.
  2. Based on the code you posted, you have to do this:

    Route::get('role', 'TestController@index');
    

    Your namespace should be protected $namespace = 'App\Http\Controllers'; (see App instead of app). I would still recommend to use the new way Laravel routing system works, do not use a namespace in your route service provider and just use the FQDN on your route file


    If they are using ->namespace($this->namespace), they must use the old way = 'TestController@index'.

    Login or Signup to reply.
  3. Try this

    use AppHttpControllersTestController;
    

    respect characters 😁

    i hope it was useful

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search