6 months ago

How to get pivot table relationship products by category id

Posted 6 months ago by tehseen

i have relationship in product & category many to many with pivot table i was try to filter product with category like below

$products = Product::where(function($query){

$category = Input::has('filtercategory') ? Input::get('filtercategory') : null;

if(isset($category)) {
      $query-> where('category.id', '=', $category);


but i have this below error can any one help

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'category.id' in 'where clause' (SQL: select count(*) as aggregate from `products` where (`category`.`id` = 1))

Please sign in or create an account to participate in this conversation.