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?
2
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:
Note that it is a convention to make your resources plural rather than singular.
You can accomplish a lot using scoped nested resources and shallow nesting:
Route::apiResource('products', ProductController::class); Route::apiResource('products.categories', ProductCategoryController::class);
Route::apiResource('products', ProductController::class); Route::apiResource('products.categories', ProductCategoryController::class)->shallow();
Click here to cancel reply.
2
Answers
You can solve the missing parameter names using the parameters method.
That should give you the following:
Note that it is a convention to make your resources plural rather than singular.
You can accomplish a lot using scoped nested resources and shallow nesting: