title: Laravel update hasMany relationship
body: <p>I just read more documentation and issues for this problem to resolve that , but nothing work for me, i have 2 table wit this models:</p>
  
  <pre><code>class Month extends Model
  {
      protected $guarded = ['id'];
  
      public function lessons()
      {
          return $this-&gt;hasMany(Lesson::class);
      }
  }
  
  class Lesson extends Model
  {
      protected $guarded = ['id'];
  
      public function months()
      {
          return $this-&gt;belongsTo(Month::class);
      }
  }
  </code></pre>
  
  <p>I can save some data with relation ship with this sample code and that work fine:</p>
  
  <pre><code>$month = Month::find(1);
  
  $lesson = new Lesson();
  $lesson-&gt;title = $request-&gt;title;
  $lesson-&gt;content = $request-&gt;content;
  $lesson-&gt;file_url = $uploadedFilePath;
  $lesson-&gt;filename = $filename;
  $lesson-&gt;time = $request-&gt;time;
  
  $month = $month-&gt;lessons()-&gt;save($lesson);
  </code></pre>
  
  <p>now I try to update some lesson fields with this code:</p>
  
  <pre><code>$lesson = Lesson::find($id);
  
  $lesson-&gt;update([
      'title'    =&gt; $request-&gt;title,
      'content'  =&gt; $request-&gt;content,
      'file_url' =&gt; $uploadedFilePath,
      'filename' =&gt; $filename,
      'time'     =&gt; $request-&gt;time
  ]);
  
  $month = Month::find($request-&gt;months['0']);
  
  $lesson = Lesson::find($lesson-&gt;id);
  $lesson-&gt;months()-&gt;associate($month)-&gt;save();
  </code></pre>
  
  <p>in that I try to change <code>month_id</code> column on <code>Lesson</code> table in database with for example <code>$month-&gt;id</code> value, how can I do that?</p>
  
  <p><strong>UPDATED:</strong></p>
  
  <pre><code>class Lesson extends Model
  {
      protected $guarded = ['id'];
  
      public function month()
      {
          return $this-&gt;belongsTo(Month::class);
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>$lesson-&gt;update([
      'title' =&gt; $request-&gt;title,
      'content' =&gt; $request-&gt;content,
      'file_url' =&gt; $uploadedFilePath,
      'filename' =&gt; $filename,
      'time' =&gt; $request-&gt;time
  ]);
  
  $month = Month::find($request-&gt;months['0']);
  $lesson = Lesson::find($lesson-&gt;id);
  
  $lesson-&gt;month()-&gt;associate($month)-&gt;save();
  $lesson-&gt;update(['month_id' =&gt; $month-&gt;id]);
  </code></pre>
  
  <p>Migrations:</p>
  
  <pre><code>Schema::create('months', function (Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;string('title');
      $table-&gt;string('description');
      $table-&gt;string('price');
      $table-&gt;timestamps();
  });
  
  Schema::create('lessons', function (Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;integer('month_id')-&gt;unsigned();
      $table-&gt;string('title');
      $table-&gt;longText('content');
      $table-&gt;string('file_url');
      $table-&gt;string('filename');
      $table-&gt;string('time', 50);
      $table-&gt;foreign('month_id')-&gt;references('id')-&gt;on('months')-&gt;onDelete('cascade');
      $table-&gt;timestamps();
  });
  </code></pre>