tehseen
6 months ago
1157
7
General

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);
}

})->paginate(24);

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.