Dru*_*jen 83
你可以使用eruque(如下)的toArray().
该toArray
方法将集合转换为普通的PHP数组.如果集合的值是Eloquent模型,则模型也将转换为数组
$comments_collection = $post->comments()->get()->toArray()
Run Code Online (Sandbox Code Playgroud)
eit*_*hed 13
使用all()
方法 - 它旨在返回集合项目:
/**
* Get all of the items in the collection.
*
* @return array
*/
public function all()
{
return $this->items;
}
Run Code Online (Sandbox Code Playgroud)
par*_*oid 11
尝试这个:
$comments_collection = $post->comments()->get()->toArray();
Run Code Online (Sandbox Code Playgroud)
看看这可以帮助你
集合中的 toArray() 方法