I am creating an application in Laravel which has 3 models with relationships to each other.
I have got a problem in routing where I show particular category according to the id. I do like this:
Route::apiResource('/categories', 'Core\CategoryController');
Route::prefix('categories')->group(function() {
Route::apiResource('/{category}/sub_categories', 'Core\SubCategoryController');
Route::prefix('sub_categories')->group(function() {
Route::apiResource('/{sub_category}/sub_sub_categories', 'Core\SubSubCategoryController');
});
});
I am able to do http://localhost:8080/api/categories/3/sub_categories
. However, I am not able to do http://localhost:8080/api/categories/3/sub_categories/1/sub_sub_categories
. I am not able to get the id of category and display it in url. What I am able to do is this -> http://localhost:8080/api/categories/sub_categories/1/sub_sub_categories
So, how can I display the id of category in that URL?
I tried:
Route::prefix('/{category}/sub_categories')->group(function() {
Route::apiResource('/{sub_category}/sub_sub_categories', 'Core\SubSubCategoryController');
});
However, that didn't work as expected.