Tengo dos modelos relacionados: Categoryy Post.
El Postmodelo tiene un publishedalcance (método scopePublished()).
Cuando trato de obtener todas las categorías con ese alcance:
$categories = Category::with('posts')->published()->get();
Me sale un error:
Llamar al método indefinido
published()
Categoría:
class Category extends \Eloquent
{
public function posts()
{
return $this->HasMany('Post');
}
}
Enviar:
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();Category::has('postsPublished')en este caso