title: Associate() in laravel
body: <p>I have 2 models, a User and an Address. I am still experimenting on associate() since I read it in <a href="https://laravel.com/docs/5.6/eloquent-relationships#updating-belongs-to-relationships" rel="nofollow noreferrer">https://laravel.com/docs/5.6/eloquent-relationships#updating-belongs-to-relationships</a> but I'm having some trouble with implementing it and sadly my video tutorial doesn't cover the associate() function.</p>
  <pre><code>class User extends Authenticatable
        public function address() {
        return $this-&gt;hasOne('App\Address');
  }
  
  class Address extends Model
        public function user() {
        return $this-&gt;belongsTo('App\User');
  }
  
  // --web.php--
  
  Route::get('/sample',function(){
  $user = User::create(['name'=&gt;'user 1','email'=&gt;'user@laravel.com',password='']);
  $address = Address::create(['name'=&gt;'sample address of user 1']);
  
  $address-&gt;user()-&gt;associate($user);
  
  });
  </code></pre>
  <p>Everything was saved, but I was expecting that user_id of the address would be 1. Instead, user_id of the address was set to NULL. Isn't associate() suppose to link a specific 'belongsTo' model to its parent by automatically assigning the foreign key equal to the parent's ID? BTW im very new to PHP and Laravel so yeah..</p>