I\'m working on a project in Laravel. I have an Account model that can have a parent or can have children, so I have my model set up like so:
public
I've created a package that uses common table expressions (CTE) to implement recursive relationships: https://github.com/staudenmeir/laravel-adjacency-list
You can use the descendants relationship to get all children of an account recursively:
class Account extends Model
{
use \Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;
}
$allChildren = Account::find($id)->descendants;