title: Save object with foreign keys in laravel
body: <p>I use PHP, Laravel 5.2 and MySQL.</p>
  
  <p>During user registration, I need to create a new Patient. But, Patient has user id, contact id and guardian id(foreign keys). </p>
  
  <p>When I try to save() the patient, I get the following exception:</p>
  
  <blockquote>
    <p>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'patient_id' in
    'field list' (SQL: update <code>users</code> set <code>patient_id</code> = 0, <code>updated_at</code> =
    2016-06-07 12:59:35 where <code>id</code> = 6)</p>
  </blockquote>
  
  <p>The problem is that I DO NOT have <strong>patient_id</strong> column. Instead I have <strong>patientId</strong>. </p>
  
  <p>I don't know how to fix this issue. Any help will be appreciated. I can include the migration files if this is important.</p>
  
  <p><strong>UserController.php</strong></p>
  
  <pre><code>public function postSignUp(Request $request)
  {
      $this-&gt;validate($request,[
          'email' =&gt; 'required|email|unique:users',
          'name' =&gt; 'required|max:100',
          'password' =&gt; 'required|min:6'
      ]);
  
  
      $guardian = new Guardian();
      $guardian-&gt;guardianId = Uuid::generate();;
      $guardian-&gt;save();
  
      $contact = new Contact();
      $contact-&gt;contactId = Uuid::generate();
      $contact-&gt;save();
  
      $user = new User();
      $user-&gt;email = $request['email'];
      $user-&gt;name = $request['name'];
      $user-&gt;password = bcrypt($request['password']);
      $user-&gt;save();
  
  
      $patient = new Patient();
      $patient-&gt;patientId = (string)Uuid::generate();
      $patient-&gt;user()-&gt;save($user);
      $patient-&gt;contact()-&gt;save($contact);
      $patient-&gt;guardian()-&gt;save(guardian);
  
  
  
      $patient-&gt;save();
      Auth::login($user);
  
  //        return redirect()-&gt;route('dashboard');
  }
  </code></pre>
  
  <p><strong>Patient.php</strong></p>
  
  <pre><code>class Patient extends Model
  {
      protected $primaryKey='patientId';
      public $incrementing = 'false';
      public $timestamps = true;
  
      public function user()
      {
          return $this-&gt;hasOne('App\User');
      }
      public function contact()
      {
          return $this-&gt;hasOne('App\Contact');
      }
      public function guardian()
      {
          return $this-&gt;hasOne('App\Guardian');
      }
      public function allergies()
      {
          return $this-&gt;belongsToMany('App\PatientToAllergyAlert');
      }
      public function medicalAlerts()
      {
          return $this-&gt;belongsToMany('App\PatientToMedicalAlert');
      }
  }
  </code></pre>
  
  <p><strong>User.php</strong></p>
  
  <pre><code>class User extends Authenticatable
  {
      protected $fillable = [
          'name', 'email', 'password',
      ];
      protected $hidden = [
          'password', 'remember_token',
      ];
      public function patient()
      {
          return $this-&gt;belongsTo('App\Patient');
      }
  }
  </code></pre>
  
  <p><strong>Contact.php</strong></p>
  
  <pre><code>class Contact extends Model
  {
      protected $table = 'contacts';
      protected $primaryKey = 'contactId';
      public $timestamps = true;
      public $incrementing = 'false';
  
      public function contact()
      {
          return $this-&gt;belongsTo('App\Patient');
      }
  }
  </code></pre>
  
  <p><strong>Guardian.php</strong></p>
  
  <pre><code>class Guardian extends Model
  {
      protected $table = 'guardians';
      protected $primaryKey = 'guardianId';
      public $timestamps = true;
      public $incrementing = 'false';
  
      public function contact()
      {
          return $this-&gt;belongsTo('App\Patient');
      }
  }
  </code></pre>