srph/laravel-collection-shallow-to-array

此包已被弃用且不再维护。未建议替代包。

将 Collection 应用于浅层 toArray

v0.1.0 2016-01-05 20:20 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:54:32 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

将浅层 toArray 应用于 Collection

弃用通知

使用 Collection#all 代替。此实用工具没有意义;由作者的懒惰阅读 API 文档而产生。

嗯?

调用 Eloquent 模型(例如,User::all())中的 toArray 也会将 toArray 应用于集合中的每个项目。以下是与 Collection toArray 的比较

- User::all()->toArray(); // [[], [] []];
+ collection_shallow_to_array(User::all()); // [User, User, User]

安装

composer require srph/laravel-collection-shallow-to-array

用法

$users = Users::all();
$array = collection_shallow_to_array($users);