title: "Call to undefined method Illuminate\\Database\\Query\\Builder::users() using Laravel
body: <p>My controller code:</p>
  <pre><code>public function addGroup(Request $request)
  {
      $validator = UserValidations::validateGroups($request-&gt;all());
  
      if($validator-&gt;fails()) {
          return response(['status' =&gt; false, 'message' =&gt; 'Validation Errors', 'errors' =&gt; $validator-&gt;errors()-&gt;all()], 500);
      }
  
      try {
  
          $request-&gt;request-&gt;add(['created_by' =&gt; Auth::user()-&gt;id]);
          $group = $this-&gt;group-&gt;create($request-&gt;only($this-&gt;group-&gt;getModel()-&gt;fillable));
  
          if(!empty($request-&gt;get('group_members')))
          {
              $groupMembers = Group::where('id', $group-&gt;id);
              $groupMembers-&gt;users()-&gt;attach($request-&gt;get('group_members'));
          }
  
  
          return response(['status' =&gt; true, 'message' =&gt; 'Group added', 'data' =&gt; $group], 500);
  
      } catch (\Exception $ex) {
          return response(['status' =&gt; false, 'message' =&gt; 'Validation Errors', 'errors' =&gt; $ex-&gt;getMessage()], 500);
      }
  }
  </code></pre>
  <p>My Group Model where there is relationship</p>
  <pre><code>public function users()
  {
      return $this-&gt;belongsToMany('App\Models\Users\User', 'group_members');
  }
  </code></pre>
  <p>My request parameter:</p>
  <pre><code>{
      &quot;name&quot;: &quot;CM&quot;,
      &quot;group_members&quot;: [74,75]
  }
  </code></pre>
  <p>I want to assign group name with group members (users) and creating group name as well but I am getting error of <code>Call to undefined method Illuminate\\Database\\Query\\Builder::users()</code></p>
  <p>Where I am going wrong?</p>