Forum

Multiply search in key value table

I am using laravel-5.4

table:

| item_id | option_id | value |
|---------|-----------|-------|
| 1       | 1         | test1 |
| 2       | 1         | test  |
| 3       | 1         | test1 |
| 4       | 2         | test1 |
| 5       | 2         | test  |
| 1       | 2         | test2 |
| 2       | 2         | test  |
| 3       | 3         | test  |
| 3       | 2         | test2 |
| 5       | 3         | test  |

I want to select item_id using multiple query

        select('item_id')
            ->where( function ( $query )
            {
                $query
                    ->where('option_id', 1)
                    ->where('value', 'test1');
            })
            ->where( function ( $query )
            {
                $query
                    ->where('option_id', 2)
                    ->where('value', 'test2');
            })
            ->get();

The result should be [1,3]

But the result is empty

Stalkerok
Stalkerok
  • 1 week ago