J'ai deux modèles liés: Categoryet Post.
Le Postmodèle a une publishedportée (méthode scopePublished()).
Quand j'essaye d'obtenir toutes les catégories avec cette portée:
$categories = Category::with('posts')->published()->get();J'obtiens une erreur:
Appel à une méthode non définie
published()
Catégorie:
class Category extends \Eloquent
{
    public function posts()
    {
        return $this->HasMany('Post');
    }
}Publier:
class Post extends \Eloquent
{
   public function category()
   {
       return $this->belongsTo('Category');
   }
   public function scopePublished($query)
   {
       return $query->where('published', 1);
   }
}
Category::whereHas('posts', function ($q) { $q->published(); })->get();