'Why there is an error with the resource controller?
I have an Admin folder with UserController (resource) inside
--Controllers
--Admin
-- UserController.php
In web.php I have the following routes:
use App\Http\Controllers\Admin\UserController;
Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function (){
Route::get('/', [HomeController::class, 'index']);
Route::resource('user', UserController::class);
});
UserController
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index()
{
return view('admin.user.index');
}
}
When I try to go to admin/user I get an error
Target class [Admin\App\Http\Controllers\Admin\UserController] does not exist.
I will be grateful for the hint.
Solution 1:[1]
You set the namespace to Admin so it adds it in the base namespace. Just remove the namespace. It should work.
Route::group(['prefix' => 'admin'], function (){
Route::get('/', [HomeController::class, 'index']);
Route::resource('user', UserController::class);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Karl Mounguengui |
