Question Details

No question body available.

Tags

php laravel

Answers (1)

Accepted Answer Available
Accepted Answer
April 11, 2025 Score: 3 Rep: 560 Quality: High Completeness: 60%

Arr::collapse() accepts only one argument and it must be an array of arrays.

In your loop, you're passing multiple arguments:

$data = Arr::collapse($data, $query->where(...)->get()->toArray());

Only the first argument is used and the second is ignored.

Internally it works like this:

public static function collapse($array)
{
    $results = [];

foreach ($array as $values) { if ($values instanceof Collection) { $values = $values->all(); } elseif (! isarray($values)) { continue; }

$results[] = $values; }

return array
merge([], ...$results); }

I don't know exactly how your loop works but you can try to do the following:

$data = [];

for (...) { $data[] = $query->where('some_field', $someParameter)->get()->toArray(); }

$data = Arr::collapse($data);