Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

php - Laravel 8: Target class [ProductController] does not exist

I'm using Laravel-8 to develop my project, and I have a resource controller named ProductController which is placed at Admin directory inside Controllers, just like this image is showing:

capture

Then at my route file, I coded this:

Route::resource('products', 'ProductController');
Route::resource('permissions', 'PermissionController');

But when I want to go to products route, I get this message:

IlluminateContractsContainerBindingResolutionException Target class [AppHttpControllersAdminProductController] does not exist.

Now you may say in Laravel-8, I have to use Route::get('/', ProductController::class);, but as you can see above, I have also determined a permissions route to PermissionController by the old method and it is working completely fine!

The namespace of Admin is also specified at RouteServiceProvider:

Route::middleware(['web' , 'auth' , 'auth.admin'])
                ->namespace('AppHttpControllersAdmin')
                ->prefix('admin')
                ->group(base_path('routes/web/admin.php'));

Note that I also tried Route::resource('products', ProductController::class); , but still get the same error.

I guess the issue is coming from another part!

So if you have any idea about this, please let me know, I would really appreciate any idea or suggestion from you guys...

Thanks in advance.

UPDATE #1:

ProductController goes like this:

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppHttpControllersController;
use AppModelsProduct;
question from:https://stackoverflow.com/questions/65856338/laravel-8-target-class-productcontroller-does-not-exist

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your namespace at your Controller is wrong, it should be:

namespace AppHttpControllersAdmin;

Because the Controller is placed at Admin directory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...