title: Defining Laravel Relationship in Custom Primary Key and Foreign Key
body: <p>I have 2 tables and It is One to One Relationship Model Type.</p>
  <p>Students Table = id|nik|name|address. Accounts Table = id|nik|username|password.</p>
  <p>In this case every student has one account and i took NIK as the $primaryKey in student model. How to define a relationship for that? Thanks in advance.</p>
  <pre><code>// Student Model
  public function account()
  {
      return $this-&gt;hasOne(Account::class, 'nik', 'nik');
  }
  
  // Account Model
  public function student()
  {
      return $this-&gt;belongsTo(Student::class, 'nik', 'nik');
  }
  </code></pre>