I have separated my project routes into home.php
that contains the client-side routes and admin.php
that contains server-side routes.
So here is my RouteServiceProvider.php
:
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web/home.php'));
Route::middleware(['web', 'auth.admin'])
->namespace($this->namespace . '\Admin')
->prefix('admin')
->group(base_path('routes/web/admin.php'));
});
}
So as you see I have specified ->namespace($this->namespace . '\Admin')
because of Admin Controllers that are placed in this directory:
App\Http\Controllers\Admin\...
Then in the admin.php
, I added this route:
Route::resource('users', UserController::class);
But I get this error:
Target class [Admin\UserController] does not exist.
So what's going wrong here? How can I solve this issue and properly call the Controller from Admin?
CodePudding user response:
You might need to add a use
statement to point out where your controller lies within the route file.
For example:
use App\Http\Controllers\Admin\UserController;
CodePudding user response:
The namespace changes are correct.
The problem is a missing using.
So to correct it, change in your route file:
use App\Http\Controllers\Admin\UserController; // <-- add this.
Route::resource('users', UserController::class);