title: Saving one to one relation in Laravel
body: <p>A <code>User</code> has one (or zero) <code>Company</code>, and a <code>Company</code> belongs to one and only one <code>User</code>. I try to save a company for a user but it adds a new entry in database every time I re-trigger the save method. It's a one to one relation, so I though <code>save</code> method on <code>User</code>.</p>
  
  <p>So <code>Company</code> has one method <code>user()</code>:</p>
  
  <pre><code>public function user() {
      return $this-&gt;belongsTo(User::class, 'user_id');
  }
  </code></pre>
  
  <p>And <code>User</code> has one method <code>company()</code>:</p>
  
  <pre><code>public function company() {
      return $this-&gt;hasOne(Company::class, 'user_id');
  }
  </code></pre>
  
  <p>I'm trying to save (so create or update) a user's company like this (in a Controller):</p>
  
  <pre><code>$company = new Company();
  $company-&gt;name = 'Test';
  User::findOrFail(1)-&gt;company()-&gt;save($company);
  </code></pre>
  
  <p>First time I run this code it creates the entry in database (OK), but second time it adds a new entry for the same user (Not OK). I thought it will only update the database entry.</p>
  
  <p>Is it a glitch (or something I don't understand in one to one relation) in Laravel or <strong>am I doing something wrong?</strong> (I think and hope it's the second purpose)</p>