具有不同深度级别的分层数据 - 递归函数

I have a hierarchical table of vehicles. I want to write recursive function which find all descendants of given id. I want to do it without using path column. For example: find_children(2) sholud return array of ids [6,7,14,10,11,12,13,17,18,19,15,16]

enter image description here

I wrote function

public static function find_children ($id)
{
    is_array($id)?$ids=$id:$ids[]=$id;
    static $tab=[];
    $results=DB::table('vehicles')->whereIn('parent_id',$ids)->pluck('id');
    $how_many=DB::table('vehicles')->whereIn('parent_id',$ids)->count();
    if($how_many==0){
        return $tab;
    }

    $tab[]=$results;
    return  self::find_children($res);
}

For given example I receive array of [6,7,14] in first iteration and array of [10,11] in the second one. I think the problem is different levels of depth in hierarchy. I don't know how to come back from level (a3,a4) up to (audi) and then (bmw) Please give me some help.

Try with two function like below. let me know if you got any error.

public function getData($id)
{

    $vehicles =DB::table('vehicles')->get();

    return  $this->find_children($vehicles,$id);
}

public function find_children($vehicles,$id)
{
    $ids = [];
    foreach($vehicles as $v)
    {
        if($id == $v->parent_id)
        {
            $ids[] = $v->id;

            $childids = $this->find_children($vehicles,$v->parent_id);

            $ids = array_merge($ids,$childids);
        }
    }
    $response = array_unique($ids);
    return $response;
}