title: updating a relationship in laravel
body: <p>I have a model that has a relationship like this</p>
  
  <pre><code>public function users(){
      return $this-&gt;belongsToMany(User::class);
  }
  public function latestUrlStatus(){
      return $this-&gt;hasOne(UrlStatus::class)-&gt;latest();
  }
  </code></pre>
  
  <p>from my controller i can save from <code>many to many relationship</code> like this (SUCCESS NO PROBLEM)</p>
  
  <pre><code>public function update(Request $request, $id)
  {
      $updateUrl = Url::findOrFail($id);
      $updateUrl-&gt;url = $request-&gt;input('url');
      $updateUrl-&gt;description = $request-&gt;input('description');
      $updateUrl-&gt;users()-&gt;sync(array_pluck($request-&gt;input('selectedTags'), 'id'));
      $updateUrl-&gt;save();
  
          if($updateUrl){
              return new UrlsResource($updateUrl);
          }
  }
  </code></pre>
  
  <p>but when i add this code to save from another relation</p>
  
  <pre><code>public function update(Request $request, $id)
  {
      $updateUrl = Url::findOrFail($id);
      $updateUrl-&gt;url = $request-&gt;input('url');
      $updateUrl-&gt;description = $request-&gt;input('description');
      $updateUrl-&gt;users()-&gt;sync(array_pluck($request-&gt;input('selectedTags'), 'id'));
      $updateUrl-&gt;save();
  
      //THIS CODE UP TO LAST
      $httpCode = check_http_header($request-&gt;input('url'));
      $status = "UP";
  
      $url = Url::with('latestUrlStatus','users')-&gt;findOrfail($id);
      $updateUrl-&gt;latestUrlStatus()-&gt;status_code = $httpCode;
      $updateUrl-&gt;latestUrlStatus()-&gt;status = $status;
      $updateUrl-&gt;push();
      if($updateUrl){
         return new UrlsResource($updateUrl);
      }
  }
  </code></pre>
  
  <p>it doesnt update the latest url status. I'm sorry just new to framework. Thanks in advance.</p>