混淆了 array 与 collection,join 并不支持 collection.laravel
$collection = collect([1, 2, 3]);
$collection->toArray();
若是 collection 中的 item 是 model,那么git
全部的 eloquent 查询返回都是一个 collection 实例,而不是 array。github
laravel tinker 中测试json
$a = collect([1, 2, 3])->all() >>> gettype($a) => "array" >>> $c = collect([1, 2, 3]) >>> gettype($c) => "object" >>> get_class($c) => "Illuminate\Support\Collection" >>> get_class($a) PHP Warning: get_class() expects parameter 1 to be object, array given on line 1
可见,gettype 能够判断是不是 array,可是 gettype 没法直接得知具体的 object 对应的 class,须要调用 get_class。测试
https://github.com/tightenco/collectspa