我是 Laravel 的初学者。我在使用 Laravel 时遇到了一些小问题。
我有这个代码:
$categories = $categoryRepository->descendantsAndSelf($slug ?? null);
这个返回:
Illuminate\Support\Collection {#535 ▼
#items: array:17 [▼
0 => 1
1 => 2
2 => 3
3 => 4
4 => 5
5 => 6
6 => 7
7 => 8
8 => 9
9 => 10
10 => 11
11 => 12
12 => 13
13 => 14
14 => 15
15 => 16
16 => 17
]
}
还有我的存储库:
public function getProductFromIdCategories($categories)
{
return $this->model->select('name', 'slug', 'products.id', 'small_description')->with(['selectedCategory', 'frontImage'])->active()->leftJoin('selected_product_categories', function ($join) {
$join->on('products.id', 'selected_product_categories.product_id');
})->whereIn('selected_product_categories.category_id', $categories)->get();
}
当我运行我的代码时:
dd($this->model->getProductFromIdCategories($categories->toArray()));
当年话下