title: LARAVEL : Destroy and detach method
body: <p>I'm trying to delete a Poll with this function where I need to detach relations :</p>
  
  <pre><code>public function destroy($id)
  {
      $poll = Poll::findOrFail($id);
      $poll-&gt;answers()-&gt;detach();
      $poll-&gt;poll_user()-&gt;detach();
      $poll-&gt;delete();
  }
  </code></pre>
  
  <p>But I'm getting this error message, I don't know why :</p>
  
  <blockquote>
    <p>Call to undefined method Illuminate\Database\Query\Builder::detach()</p>
  </blockquote>
  
  <p>Here is the Poll model :</p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Poll extends Model
  {
  
      /**
       * La table utilisée par le modèle
       *
       * @var string
       */
      protected $table = 'polls';
  
      /**
       * On utilise les dates de mise à jour
       *
       * @var bool
       */
      public $timestamps = true;
  
      /**
       * Attributs autorisés en ensignement de masse.
       *
       * @var array
       */
      protected $fillable = ['question'];
  
      /**
       * Relation de type 1:n
       *
       * @return Illuminate\Database\Eloquent\Relations
       */
      public function answers()
      {
          return $this-&gt;hasMany('App\Models\Answer');
      }
  
      /**
       * Relation de type n:n
       *
       * @return Illuminate\Database\Eloquent\Relations
       */
      public function users()
      {
          return $this-&gt;belongsToMany('App\Models\User')-&gt;withTimestamps();
      }
   }
  </code></pre>