|
20 | 20 | return $request->user();
|
21 | 21 | });
|
22 | 22 |
|
23 |
| -// API route all methods are same like ResourceController |
24 |
| -// index, |create, store($request)|, show($id), |edit($id), update($request, $id)|, destroy($id) |
| 23 | +/** |
| 24 | + * Note: Default resourceful controller syntax is something like this |
| 25 | + * Route::resource('categories', CategoryController::class); |
| 26 | + * |
| 27 | + * The resourceful controller has 7 methods which are defined by default at the time of creation. |
| 28 | + * index, [ create, store($request) ], show($id), [ edit($id), update($request, $id) ], destroy($id) |
| 29 | + * |
| 30 | + * There is also a Api resource but the Api resource has 5 methods. |
| 31 | + * i.e. |
| 32 | + * index() |
| 33 | + * show(Category $category) |
| 34 | + * store(Request $request), |
| 35 | + * update(Category $category, StoreCategoryRequest $request) |
| 36 | + * destroy(Category $category) |
| 37 | + */ |
| 38 | + |
| 39 | +/* |
25 | 40 | // Now we have to create the Category API
|
26 | 41 | Route::get('categories', [CategoryController::class, 'index']);
|
27 | 42 |
|
|
33 | 48 | Route::put('/categories/{category}', [CategoryController::class, 'update']);
|
34 | 49 | // categories delete method
|
35 | 50 | Route::delete('/categories/{category}', [CategoryController::class, 'destroy']);
|
| 51 | +*/ |
36 | 52 |
|
| 53 | +/** |
| 54 | + * I commented all the above API routes because I want to use "API resource" which is |
| 55 | + * builtin Laravel feature and clean way for the API CRUD which behind the scenes using |
| 56 | + * all these 5 methods. |
| 57 | + */ |
| 58 | +Route::apiResource('categories', CategoryController::class); |
37 | 59 |
|
38 | 60 | // Product API
|
39 | 61 | Route::get('products', [ProductController::class, 'index']);
|
|
0 commit comments