Home > Software design >  Laravel, how to search for product features? get the ids where every item in array is present in tab
Laravel, how to search for product features? get the ids where every item in array is present in tab

Time:03-30

I have a table with product features table structure below
..|product_id | feature_id|created_at
..|1 | 5 |time_stamp
..|1 | 6 |time_stamp

..|2 | 6 |time_stamp

..|2 | 9 |time_stamp
.
.
.

how to write query to search with array [5,6] and get result of product id 1

CodePudding user response:

You can try like

product_feature_data is a model name

Proudct::whereHas('product_feature_data',function($q) {
  $q->whereIn('feature_id', [5,6]);
})->get();
  • Related