我试图使用Laravel 5(L5)Model :: with()方法获得具有给定类别的产品的简单列表。但是L5似乎忽略了where子句的分类。Laravel 5 Model :: with()行为
在我的产品型号的关系:
public function categories(){
return $this->belongsToMany('App\Category', 'categories_products');
}
在我的控制器:
public function getByCategory($slug){
$return = Product::with(array('categories' => function($query) use ($slug){
$query->where('slug', 'like', $slug);
}))->paginate(60);
dd($return);
}
结果是在我的数据库中的每个产品的列表,而不是仅仅是那些具有列表给予类别slu。。
我试过硬编码在某些不同的where子句中,但似乎都忽略了。我错过了什么吗?
我不熟悉laravel。但是,您可以使用Xdebug进行调试。当然,这会帮助你很多。对于Xdebug配置,您可以使用此链接http://blog.thecodingmachine.com/content/setting-xdebug-debugging-environment-php-wamp-eclipse-pdt – 2015-02-10 12:05:50