i have category table, and sub categories also in same table... if some category have null parent_id its top node category. table basic fields like this:
---------------------
|id |name |parent_id|
---------------------
I just need to get all childs ids in minimum quarry execution: eg:
Category::find(2)->allChildIds(); //result like [3,4,6,10,....]
i have this relationship added:
public function parent(){
return $this->belongsTo(Category::class);
}
public function childs(){
return $this->hasMany(Category::class,'parent_id');
}
thank you