How to do a dynamic query with multiple rows in laravel mysql

  laravel, php

I have a query for a single id where I get reviews for a single id

public function getReviews($placeId, $limit, $orderColumn, $orderDirection)
    $place = Place::withTrashed()
        ->with(['reviews' => function (HasManyThrough $query) use ($limit, $orderColumn, $orderDirection) {
            if ($orderColumn != 'random') {
                if ($orderColumn != 'custom') {
                    $query->orderBy($orderColumn, $orderDirection);
            } else {
        ->where('id', '=', $placeId)
    return $place->reviews;

I want to convert this query for multiples ID and dynamic number of ID’s

Actually I want to replace that placeId for multiples placeId

I have an array called locationGroup that can have multiple keys and I want to use all the placeId that are located here

this is the way to access to one of the placeId (using the first of the array as an example)


currently, the query returns an array with all the "reviews" of a single placeId. I am looking to "mix" this result with the reviews belonging to all the $locationGroup[KEY]->place_id

enter image description here

how can I do?

Source: Laravel

Leave a Reply