如何从 laravel 5.2 中的 collection 访问数据

How to access data from collection in laravel 5.2

我有这个表格的结果

RowCollection {#780 ▼
  #heading: array:7 [▶]
  #title: "Sheet1"
  #items: array:3 [▶]
}

我必须访问标题,但是当我使用 foreach 循环时

foreach( $data as $key => $value){
echo $value;
}

它打印出项目数组value.So如何访问标题数组?

根据我在 laravel 及其 var_dumper 中的经验,使用 # 签名的项目登录 dd() 输出可以作为具有以下模式的方法访问:

get{ItemStudlyCaseName}()

例如getHeading()getTitle()getItems()

+ 签名的项目可以作为属性访问。

完整描述

dd()var_dumper输出中有三个符号:

# 受保护 属性

+ public 属性

- 私人 属性

受保护的属性可以通过具有 $object->get{PropertyStudlyCaseName}() 模式的 getter 方法访问。

public 属性可以直接访问。 $object->propertyName

无法访问私有属性。

例如在请求对象中:

Request {#38 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure {#142 ▶}
  #routeResolver: Closure {#143 ▶}
  +attributes: ParameterBag {#40 ▶}
  +request: ParameterBag {#46 ▶}
  +query: ParameterBag {#46 ▶}
  +server: ServerBag {#42 ▶}
  +files: FileBag {#43 ▶}
  +cookies: ParameterBag {#41 ▶}
  +headers: HeaderBag {#44 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/"
  #requestUri: "/"
  #baseUrl: ""
  #basePath: null
  #method: "GET"
  #format: null
  #session: Store {#185 ▶}
  #locale: null
  #defaultLocale: "en"
  -isHostValid: true
  -isClientIpsValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
}

例如

# 受保护 属性 : $request->getDefaultLocale()

+ public 属性 : $request->attributes

- 私人 属性 : $request->isHostValid => returns 空