Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel雄辩地属于过滤元件_Php_Laravel_Laravel 4_Eloquent_Laravel Routing - Fatal编程技术网

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