title: laravel factory insert foreign key
body: <p>Hello everyone who's trying to help,</p>
  
  <p>im trying to create the factory file to seeding my database and i have a question how can i insert a foreign key from a table already seeded ?
  and the factory code is to have all in same file? any good pratice to this ?</p>
  
  <p><strong>Files</strong></p>
  
  <p>Model User</p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Foundation\Auth\User as Authenticatable;
  
  class User extends Authenticatable
  {
  
    protected $table = 'user'; //name of the table in database
    protected $primaryKey = 'Id'; //Primary Key of the table
  
    /**
     * Relations between tables
     */
     public function GetLoginInfo()
     {
       return $this-&gt;hasMany('App\Models\LoginInfo', 'UserId');
     }
  
     public function getStatus()
     {
       return $this-&gt;belongsTo('App\Models\AccountStatus');
     }
  
  }
  </code></pre>
  
  <p>Model Account status</p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class AccountStatus extends Model
  {
    protected $table = 'account_status'; //name of the table in database
    protected $primaryKey = 'Id'; //primary Key of the table
    public $timestamps = false; //true if this table have timestaps
    /**
     * Relations between tables
     */
     public function GetUsers()
     {
       return $this-&gt;hasMany('App\Models\Users', 'StatusId');
     }
  }
  </code></pre>
  
  <p>factory file:</p>
  
  <pre><code>&lt;?php
  /** @var \Illuminate\Database\Eloquent\Factory $factory */
  
  //Factory for Account Status table
  $factory-&gt;define(App\Models\AccountStatus::class, function (Faker\Generator $faker) {
      return [
        'Description' =&gt; $faker-&gt;word,
      ];
  });
  
  //Factory for user table
  $factory-&gt;define(App\Models\User::class, function (Faker\Generator $faker) {
      return [
        'Username' =&gt; $faker-&gt;unique()-&gt;userName,
        'Password' =&gt; bcrypt('test'),
        'Email' =&gt; $faker-&gt;unique()-&gt;safeEmail,
        'Name' =&gt; $faker-&gt;name,
        'StatusId' =&gt; Factory(App\Models\AccountStatus::class)-&gt;create()-&gt;id,
      ];
  });
  </code></pre>
  
  <p>This is what im trying to do as you can see : Factory(App\Models\AccountStatus::class)->create()->id but don't work</p>