I'm working with Laravel framework. I want to get the data for promotion with the certain category.
<b>Table</b><br>
product<br>
------<br>
id<br>
name<br>
price<br>
promotion<br>
----------<br>
id<br>
product_id<br>
discount<br>
category<br>
---------<br>
id<br>
name<br>
product_category<br>
----------------<br>
product_id<br>
category_id<br>
$promotions = Promotion::with('product')->with('category')
->whereIn('category_id', ['1','2'])
->paginate(9);
Promotion model - connect relation for product and category
// relationship with product
public function product()
{
return $this->belongsTo('App\Model\Product');
}
//relationship with category
public function category()
{
return $this->belongsToMany('App\Model\Category', 'products_categories', 'product_id', 'category_id');
}
Error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'category.id' in 'where clause' (SQL: select count(*) as aggregate from
promotions
wherecategory
.id
in (1, 2))