Iskren
Iskren

Reputation: 137

URL routing with namespace not working properly - Laravel 8

I've run into a problem with the updated version of Laravel and the new routing. The route with the resources works just fine and uses the correct namespace, the problem is with the direct route "users/table", it's not using any namespace and returns "Target class [UserController] does not exist." .

When I apply the full controller namespace and class name it works. I've modified my RouteResourceProvider.php and it's loading the default namespace on boot.

My question is why the resources method works but for the custom route, I have to specify the entire namespace inside the route group with an already set namespace?

Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin'], function () {
    Route::post('users/table', [UserController::class, 'table']);
    ...
    Route::resources([
        'users' => UserController::class,
        ...
    ]);
});

Upvotes: 1

Views: 2970

Answers (1)

Rajat
Rajat

Reputation: 19

Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'App\Http\Controllers\Admin'], function () {
Route::post('users/table', [UserController::class, 'table']);
...
Route::resources([
    'users' => UserController::class,
    ...
]);});

Upvotes: 0

Related Questions