title: How to seed self referencing table Laravel 5.1
body: <p>How can I seed a table with two foreign keys from the same table like messages:</p>
  
  <p>Migration:</p>
  
  <pre><code>    public function up()
      {
          Schema::create('messages', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;integer('to')-&gt;unsigned();
              $table-&gt;integer('from')-&gt;unsigned();
              $table-&gt;integer('parent_id')-&gt;unsigned()-&gt;nullable();
              $table-&gt;text('body');
              $table-&gt;boolean('status')-&gt;default(false);
              $table-&gt;timestamps();
          });
  
          Schema::table('messages', function (Blueprint $table) {
              $table-&gt;foreign('to')
                      -&gt;references('id')-&gt;on('users')
                      -&gt;onDelete('cascade');
  
              $table-&gt;foreign('from')
                      -&gt;references('id')-&gt;on('users')
                      -&gt;onDelete('cascade');
  
              $table-&gt;foreign('parent_id')
                      -&gt;references('id')-&gt;on('messages');
  
          });
      }
  </code></pre>
  
  <p>ModelFactory:</p>
  
  <pre><code>$factory-&gt;define(App\Message::class, function($faker) {
  
      return [
          'body' =&gt; $faker-&gt;text
          'from' =&gt; //user id,
          'to' =&gt; //user id,
          'parent_id' =&gt; //message id
      ];
  
  });
  </code></pre>
  
  <ol>
  <li>How can i get user ids here?</li>
  <li>How do I get an existing row of message for the id?</li>
  </ol>