C
C
cadaver2016-10-30 22:25:19
Laravel
cadaver, 2016-10-30 22:25:19

How to filter out belongstomany?

There are tables
places
-id
comforts
-id
comfort_place
-id
-comfort_id
-place_id
Is it possible in Place::where to filter data by id array?
you need to output place, in which there is a combination of both comfort_id = 1, and comfort_id = 2, and comfort_id = 3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrzej Wielski, 2016-10-30
@wielski

Place::whereHas('comforts', function($q){
   $q->whereIn('id', [1, 2, 3]);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question