How do I get all children that fall under a multiple parent id using eloquent for three level structure?

大憨熊 提交于 2019-12-11 14:30:01

问题


I was getting an output like this parent

child 1 ==> level 1
    Sub-child 1 ==> level 2
        sub-Sub-child  ==> level 3      
    Sub-child 2  ==> level 2
        sub-Sub-child ==> level 3 

What I need is to get an o/p like this. This was the database structure:

Each and every level to be view in level wise tables in laravel blade can anyone help to solve this parent

child 1 ==> level 1 child 2 ==> level 1 child 3 ==> level 1

Sub-child 1 ==> level 2 Sub-child 2 ==> level 2 Sub-child 3 ==> level 2

sub-Sub-child 3 ==> level 3 sub-Sub-child 3 ==> level 3 sub-Sub-child 3 ==> level 3

Code I was using in eloquent orm:

public function childs()
 {
    return $this->hasMany('App\Model  \clients','under_reference','reference_id','id')
    ->leftjoin('clients_payment_type', function($join) {
    $join->on('clients_payment_type.user_id', '=', 'clients.id');
    });
 }

Code I was using in view blade

@foreach($childs as $child)
   @if(count($child->GrandChild) > 0 )
      @include('AdminLayout.levelTwo',['childs' => $child->childs])
   @endif
@endforeach

Same as continues in laravel blade for level one 2 and three can anyone help me to solve this...

来源:https://stackoverflow.com/questions/59046609/how-do-i-get-all-children-that-fall-under-a-multiple-parent-id-using-eloquent-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!