В общем нашёл решение самостоятельно:
CONTROLLER
public function getAllCategories(){
$categories = Category::whereNull('category_id')->with('children')->get();
foreach($categories as $category){
$cats[$category->id] = $this->getAllChildrenCats($category);
}
}
public function getAllChildrenCats($category, $catsIds = []){
foreach($category->children as $children){
$catsIds[] = $children->id;
if($children->children){
$catsIds = $this->getAllChildrenCats($children, $catsIds);
}
}
return $catsIds;
}
MODEL
public function children() {
return $this->hasMany(Category::class, 'category_id')
->with('children');
}