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
Export the TestController Path using his correct namespace.
Based on the code you posted, you have to do this:
Your
namespace
should beprotected $namespace = 'App\Http\Controllers';
(seeApp
instead ofapp
). 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 fileIf they are using
->namespace($this->namespace)
, they must use the old way ='TestController@index'
.Try this
respect characters 😁
i hope it was useful