laravel-collection-shallow-to-array maintained by srph
laravel-collection-shallow-to-array
Apply a shallow toArray to a Collection.
Deprecation Notice
Use Collection#all instead. This utility doesn't make any sense; created out of author's laziness to read the API Documentation.
Huh?
Calling toArray of a Collection with Eloquent models (e.g., User::all()) also applies toArray to each item in the collection. Here's a comparison with Collection toArray:
- User::all()->toArray(); // [[], [] []];
+ collection_shallow_to_array(User::all()); // [User, User, User]
Installing
composer require srph/laravel-collection-shallow-to-array
Usage
$users = Users::all();
$array = collection_shallow_to_array($users);