Home > Mobile >  laravel php problems with array index get values
laravel php problems with array index get values

Time:04-09

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());
  • Related