skip to Main Content

I added apiResource routes in my api.php file. Although it shows all the resourceful routes for product/category, it is not showing the routes for PUT and DELETE methods in the case of products routes.

Showing 404 not found error.

Any help?

enter image description here

enter image description here

2

Answers


  1. You can solve the missing parameter names using the parameters method.

    Route::prefix('products')->group(function() {
        Route::apiResource('/', AppHttpControllersProductController::class)
            ->parameters(['' => 'product']);
        Route::apiResource('/categories', AppHttpControllersCategoryController::class);
    });
    

    That should give you the following:

    routes image

    Note that it is a convention to make your resources plural rather than singular.

    Login or Signup to reply.
  2. You can accomplish a lot using scoped nested resources and shallow nesting:

    Route::apiResource('products', ProductController::class);
    Route::apiResource('products.categories', ProductCategoryController::class);
    

    enter image description here

    Route::apiResource('products', ProductController::class);
    Route::apiResource('products.categories', ProductCategoryController::class)->shallow();
    

    enter image description here

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