title: Laravel Relations and Foreign Key Constraints
body: <p>I have two models and migrations tables. </p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Room extends Model
  {
      public function guest()
      {
          return $this-&gt;hasOne(Guest::class);
      }
  }
  </code></pre>
  
  <p>-
      
  
  <pre><code>namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Guest extends Model
  {
      public function room()
      {
          return $this-&gt;hasMany(Room::class);
      }
  }
  </code></pre>
  
  <p>room -> id, squaremeters, guest_id</p>
  
  <p>guest -> id, Name, last_name, email, phone, room_id(required)</p>
  
  <p>Room hasOne Guest -> implemented in the model</p>
  
  <p>Guest hasMany Rooms -> implemented in the model</p>
  
  <p>If I create a guest, I have to add a room Number. The room in room_table with the corresponding id should automatically be updated with the guest_id.</p>
  
  <p><strong>Example</strong>
  new Guest: id(2), Name, last_name, phone, email, room_id(3) -> The room with id 3 should show to the Guest with id 2.</p>
  
  <p>How do i implement this?</p>