Laravel Recursive Relationships
This is how you can use recursive relations: public function childrenAccounts() { return $this->hasMany(‘Account’, ‘act_parent’, ‘act_id’); } public function allChildrenAccounts() { return $this->childrenAccounts()->with(‘allChildrenAccounts’); } Then: $account = Account::with(‘allChildrenAccounts’)->first(); $account->allChildrenAccounts; // collection of recursively loaded children // each of them having the same collection of children: $account->allChildrenAccounts->first()->allChildrenAccounts; // .. and so on This way you save … Read more