Eloquent ORM: how to implement search on a related model?

Good afternoon.
There are two tables related through a third, the usual many-to-many.
Task: find all records from table A with which are associated certain records from table B.
I.e. how to find all records in the related table that are associated with a specific record from the table B, and Vice versa — is clear.
And then I have something confused. Doc read, but could something to overlook.
July 8th 19 at 16:17
1 answer
July 8th 19 at 16:19
$a_models = collect([]);
$list_of_b_models = $modelB->whereIn('id', [1,2,3])->with('relationA')->get();
forEach($list_of_b_models as $model_b) {
 $a_models = $a_models->merge($model_b->relationA);
Thank you! What you need. About and wanted to do it, but thought somehow possible without foreach'and do.
Well, for collect - thank you! - harvey commented on July 8th 19 at 16:22

Find more questions by tags LaravelORM