Filtering Eloquent collection data with $collection->filter()
The collection’s filter method calls array_filter on the underlying array, which, according to the PHP docs, preserves the array keys. This then results in your array being converted to a JavaScript object instead of an array. Call values() on your collection to reset the keys on the underlying array: $filtered_collection = $collection->filter(function ($item) { return … Read more