We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 132769b commit e596ab0Copy full SHA for e596ab0
app/Http/Controllers/Api/CategoryController.php
@@ -13,7 +13,10 @@ class CategoryController extends Controller
13
public function index(){
14
// return Category::orderBy('id')->get(); // Laravel will return as JSON format.
15
// We only want id, name filed in the response.
16
- return Category::select('id','name')->get();
+ // $categories = Category::select('id','name')->get(); This is efficient approach.
17
+ // But we are already defined our toArray response
18
+ $categories = Category::all();
19
+ return CategoryResource::collection($categories); // Now we are returning resource collection
20
}
21
22
// Route model binding
0 commit comments