Php Laravel雄辩地属于过滤元件
首先,我的模型如下所示:Php Laravel雄辩地属于过滤元件,php,laravel,laravel-4,eloquent,laravel-routing,Php,Laravel,Laravel 4,Eloquent,Laravel Routing,首先,我的模型如下所示: class Post extends Eloquent { public function url() { return $this->belongsTo('Url', 'url_id'); } } class Url extends Eloquent { public function category() { return $this->belongsTo('Category', 'catego
class Post extends Eloquent {
public function url() {
return $this->belongsTo('Url', 'url_id');
}
}
class Url extends Eloquent {
public function category() {
return $this->belongsTo('Category', 'category_id');
}
}
预期的关系是Post
具有Url
,而Url
具有类别
,因此Post
应隐式具有类别
。我试图写一个有说服力的查询,通过category\u id
过滤帖子。我有一个变量正在被传递到一个GET路由中,该路由表示category\u id
,并希望通过传递到该路由的category\u id
过滤所有帖子
感谢您的帮助
提前感谢。
有很多关系可能会对你有所帮助。像@MattBurrow一样,获取cat及其帖子,或者最好在帖子本身上使用whereHas
。