Is this possible using eloquent alone:
// build doc tree
public function tree()
{
$docs = app(config('lap.model.doc'))->with(['children.parent', 'children' => function ($query) {
return $query->orderBy('order');
}])->whereNull('parent_id')->orderBy('order')->get()->toArray();
$docs_array = [];
foreach ($docs as $doc)
{
$docs_array[] = array_except($doc, 'children');
if ($doc['children']) {
foreach ($doc['children'] as $child) {
$docs_array[] = $child;
}
}
}
return $docs_array;
}
Just curious because despite this working the way I want it to, I'm wondering if there is a better solution that might already exist within the framework capacity.