gpt4 book ai didi

php - 如何访问集合中的特定属性?

转载 作者:行者123 更新时间:2023-11-29 04:05:46 27 4
gpt4 key购买 nike

我想从练习表中访问名称属性,但我得到的是集合。我的代码看起来像。

$practice = Practice::withTrashed()->where('id',$appointment->practice_id)->get();

dd($practice);

结果看起来像

Collection {#697
#items: array:1 [
0 => Practice {#698
#dates: array:1 [
0 => "deleted_at"
]
#fillable: array:2 [
0 => "name"
1 => "email"
]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:7 [
"id" => 42
"name" => "DJ and Charlie Eye Associates"
"email" => "vendorsupport@ocuhub.com"
"created_at" => "0000-00-00 00:00:00"
"updated_at" => "2017-01-13 06:29:14"
"liferay_id" => 57238
"deleted_at" => "2017-01-13 06:29:14"
]
#original: array:7 [
"id" => 42
"name" => "DJ and Charlie Eye Associates"
"email" => "vendorsupport@ocuhub.com"
"created_at" => "0000-00-00 00:00:00"
"updated_at" => "2017-01-13 06:29:14"
"liferay_id" => 57238
"deleted_at" => "2017-01-13 06:29:14"
]
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [
0 => "*"
]
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
#forceDeleting: false
}
]
}

有什么办法可以让我得到“DJ and Charlie Eye Associates”这个名字。我使用了 withThrashed 方法,因为这个条目在练习表中被软删除了。

最佳答案

首先您需要从集合中获取一个对象,然后您可以获取该对象的任何属性:

$practice->first()->name;

或者:

$practice[0]->name;

关于php - 如何访问集合中的特定属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41635381/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com