【发布时间】:2014-01-15 02:44:49
【问题描述】:
使用 Eloquent ORM,我的模型设置如下:PostbelongsToManyCategory
Post.php
public function categories()
{
return $this->belongsToMany('Category', 'posts_categories');
}
我想按类别关系的列过滤帖子。
所以我想做这样的事情:
$posts->where('categories.slug', '=', Input::get('category_slug'));
但这不起作用。
我也试过了:
$with['categories'] = function($query){
$query->where('slug', '=', Input::get('category_slug'));
};
$posts::with($with)->get();
但我认为这是为了过滤类别而不是按类别过滤。
谁能给我指路?
【问题讨论】: