title: datatables, join same table?
body: <p>Hellooo  i am using a datatable with laravel and I have the following doubt ...</p>
  <pre><code>$query = DB::table('categories')-&gt;select('id','name','parent_id')-&gt;orderBy('id');
  </code></pre>
  <p>I have this code that returns me all the categories ...</p>
  <pre><code>columns: [
          { data: 'id' },
          { data: 'image',
        render: function ( data, type, row ) {
          return data ? '&lt;img src=&quot;/images/product/'+data+'&quot; height=&quot;80&quot; width=&quot;80&quot;&gt;' : '&lt;img src=&quot;/images/product/noproduct.jpg&quot; height=&quot;80&quot; width=&quot;80&quot;&gt;'; 
   
        }
      },
          { data: 'name' }, // used for sorting so will hide this column
          { data: 'parent_id'}
        ],
  </code></pre>
  <p>And this other code that shows me a datatable with the categories but here the dilemma enters, how do I so that in parent_id instead of showing the ID ... it shows the name, should I join the same table? but in none that shows the name of the parent_id</p>
  <p>EDIT:The same thing always happens to me, I post and find the solution at the moment, but now another question arose.</p>
  <pre><code>$query = DB::table('categories as c')-&gt;join('categories as k','c.parent_id','=','k.id')-&gt;select('c.id','c.name','k.name as namex')-&gt;orderBy('id');
  </code></pre>
  <p>This the correct way?</p>
  <p>It have a fail... the categories without parent_id... not appear how can solve it?</p>