title: Sql query where table is connected to it self and create a array using php
body: <p>I have 1 table name <code>page_live</code>. Now I want to display it if <code>isMenu = 1</code>. Now it is connected to it self with filed name <code>parent_Id</code>. </p>
  
  <p>As an example -
  I have page_live named <code>test_page</code> and this row is a parent of a row named <code>inside-1</code>. And <code>inside-1</code> is parent of <code>inside-2</code>.</p>
  
  <p>Now, I have to create array which will look like -</p>
  
  <pre><code>[0]=&gt;{
   'name' =&gt; 'test_page'
   [0]=&gt; {
    'name' =&gt; 'inside-1'
    [0] =&gt; {
      'name' =&gt; 'inside-2'
    }
   }
  }
  </code></pre>
  
  <p>This is my table - 
  <a href="https://i.stack.imgur.com/evopp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/evopp.png" alt="enter image description here"></a></p>
  
  <p>Model <code>PageLive</code></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class PageLive extends Model
  {
      protected $table = 'page_live';
  
      protected $fillable = ['name', 'adminId', 'slugName', 'description',
  'imageId', 'metaTitle', 'metaDesc', 'metaKeyword', 'pageTypeId', 'parent_id',
  'isHome', 'pageDraftId', 'themeLayoutId'];
  
      public function parent()
      {
          return $this-&gt;belongsTo(App\Http\Models\PageLive::class, 'parent_id');
      }
  
      public function children()
      {
          return $this-&gt;hasMany(App\Http\Models\PageLive::class, 'parent_id');
      }
  }
  
  </code></pre>
  
  <p>Please help me.</p>
  
  <p>Thank you.</p>