laravel : BadMethodCallException in Macroable.php line 74: Method detach does not exist
<p>I have three tables </p>

<ul>
<li><code>users</code></li>
<li><code>groups</code></li>
<li><code>group_user</code> (a pivot table which handles the membership of users in groups)</li>
</ul>

<p>I am trying to delete the membership of a user from a group like this:</p>

<pre><code>public function userDelete (Request $request, $userId)
{
    $gid = $request-&gt;group;
    $group = Group::find($gid);
    $user = User::find($userId);

    $user-&gt;groups-&gt;detach();

    // and the second method is :
    // foreach ($group-&gt;users as $user) {
    //     if ($user-&gt;pivot-&gt;user_id == $userId) {
    //         $user-&gt;detach($gid);
    //         
    //         break;
    //     }
    // }
}
</code></pre>

<p>I have tried it in may ways, but it always gives the error that the method <code>detach()</code> is not found:</p>

<blockquote>
  <p>BadMethodCallException in Macroable.php line 74:
      Method detach does not exist.</p>
</blockquote>