У меня есть две связанные модели: Category
и Post
.
Модель Post
имеет область published
(метод scopePublished()
).
Когда я пытаюсь получить все категории с этой областью:
$categories = Category::with('posts')->published()->get();
Я получаю сообщение об ошибке:
Вызов метода undefined
published()
Категория:
class Category extends \Eloquent
{
public function posts()
{
return $this->HasMany('Post');
}
}
Сообщение:
class Post extends \Eloquent
{
public function category()
{
return $this->belongsTo('Category');
}
public function scopePublished($query)
{
return $query->where('published', 1);
}
}