I have this code:
$category = Category::find($request->category_id);
$products = Product::whereIn('category_id', $category->subcategories->pluck('id')->toArray())->get();
How can get products with category ids
my code pulls products according to indexes, not according to ids. how do i get it to pull by id
CodePudding user response:
$products = Product::whereIn('category_id', $category->subcategories->select('id')->get(['id'])->toArray());