skip to Main Content

I want to use the Laravel 9 route namespace function and I wonder how to pass the namespace correctly?

Route::as('some.')->namespace('AppHttpControllersApiV1')->group(function() {
    Route::post('/store', [SomeController::class, 'store'])
        ->name('store');
});

I get the following error message:

    "message": "Target class [SomeController] does not exist.",
    "exception": "IlluminateContractsContainerBindingResolutionException",

Question: How do I do this properly?

But this works

Route::as('some.')->group(function() {
    Route::post('/store', [AppHttpControllersApiV1SomeController::class, 'store'])
        ->name('store');
});

3

Answers


  1. Well, you need to provide the right path to the controller file. For example at the top of the file put this: use AppHttpControllersController;

    Login or Signup to reply.
  2. use it :

    Route::as('some.')->namespace('ApiV1')->group(function() {
        Route::post('/store', [SomeController::class, 'store'])
            ->name('store');
    });
    
    Login or Signup to reply.
  3. Since you are using a namespace for route,so you should use

    Route::as('some.')->namespace('AppHttpControllersApiV1')->group(function() {
        Route::post('/store', 'SomeController@store')
            ->name('store');
    });
    

    Ref: https://laravel.com/docs/8.x/releases#routing-namespace-updates

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search