从 Laravel 中的 Eloquent\Collection 获取特定属性值

Getting specific attribute value from Eloquent\Collection in Laravel

我正在尝试从以下返回数据中获取属性“日期”值,如何获取?

Illuminate\Database\Eloquent\Collection {#267 ▼
  #items: array:1 [▼
    0 => App\Models\Crisis_indicators_data {#255 ▼
      #table: "crisis_indicators_data"
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:4 [▼
        "c_i_data_id" => 1
        "date" => "2022-05-23"
        "indicator_id" => 30
        "value" => 11
      ]
      #original: array:4 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▶]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
  ]
}

我试过以下方法,没有返回数据

$row_data_temp->date
$row_data_temp[0]->date
$row_data_temp[0]['date']

我不想使用 for 循环或 foreach,因为性能方面

// 获取包含所有属性的主集合...

$users = Users::get();

// 使用属性子集构建您的第二个集合。这个新的 // 集合将是普通数组的集合,而不是用户模型。

$subset = $users->map(function ($user) {
    return $user->only(['id', 'name', 'email']);
});

Whosebug 参考: