【发布时间】:2021-10-29 17:32:03
【问题描述】:
user_enabled_notifications 表有 2 行数据。我想获取id 列中的所有值。
$notificationData = UserEnabledNotifications::all();
dump($notificationData['id']); 显示Undefined index: id
dump($notificationData->id); 显示Property [id] does not exist on this collection instance
dump($notificationData[0]['id']); 仅显示 1 个 ID。我还应该尝试一次获取所有id 列值。
但是,dump($notificationData); 在下表中显示了完整的数据。
Illuminate\Database\Eloquent\Collection {#337
#items: array:4 [
0 => App\Models\UserEnabledNotifications {#338
#table: "user_enabled_notifications"
#fillable: array:3 [
0 => "userId"
1 => "notificationTypesId"
2 => "status"
]
#connection: "pgsql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [
"id" => 1
"userId" => 1
"notificationTypesId" => 1
"status" => true
"deleted_at" => null
"created_at" => null
"updated_at" => null
]
#original: array:7 [
"id" => 1
"userId" => 1
"notificationTypesId" => 1
"status" => true
"deleted_at" => null
"created_at" => null
"updated_at" => null
]
#changes: []
#casts: array:1 [
"deleted_at" => "datetime"
]
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [
0 => "*"
]
#forceDeleting: false
#enableLoggingModelsEvents: true
#oldAttributes: []
}
1 => App\Models\UserEnabledNotifications {#339
#table: "user_enabled_notifications"
#fillable: array:3 [
0 => "userId"
1 => "notificationTypesId"
2 => "status"
]
#connection: "pgsql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [
"id" => 2
"userId" => 1
"notificationTypesId" => 2
"status" => true
"deleted_at" => null
"created_at" => null
"updated_at" => null
]
#original: array:7 [
"id" => 2
"userId" => 1
"notificationTypesId" => 2
"status" => true
"deleted_at" => null
"created_at" => null
"updated_at" => null
]
#changes: []
#casts: array:1 [
"deleted_at" => "datetime"
]
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [
0 => "*"
]
#forceDeleting: false
#enableLoggingModelsEvents: true
#oldAttributes: []
}
【问题讨论】:
标签: php laravel postgresql eloquent laravel-8