public function childrenDevices() {
$categories = $this->descendants()->pluck("id");
return Device::whereHas("categories", function ($query) use ($categories) {
$query->whereIn("category_id", $categories);
});
}
SELECT DISTINCT `device_id` FROM `category_device` WHERE `category_id` in (3, 4, 5)