php - 无法访问 laravel 对象属性
问题描述
我有一个问题,我似乎无法从 laravel 中的控制器获得返回的属性。
$machineLogs = MachineLog::whereHas( 'groups', function( $group ) use (&$componentId) {
$group->whereHas( "units", function( $unit ) use (&$componentId) {
$unit->whereHas( "components", function( $component ) use (&$componentId) {
$component->where( "Component", $componentId );
} );
} );
} )->take( $limit )->get();
foreach ($machineLogs as $log)
{
echo $log->oId;
}
我似乎无法访问返回的对象的任何属性,但是我可以取回关联的数组,我做错了什么?
[
{
"oId": 411197,
"active": false,
}
]
对象本身具有我试图达到的不同属性,例如 $log->oId 以从日志中取回 oId。
我可以访问与 MachineLog 模型相关的组。{转储($log)的结果;}
App\MachineLog {#388 ▼
#primaryKey: "Oid"
#table: "Log"
#connection: "testdb"
#appends: array:1 [▼
0 => "groups"
]
#fillable: array:2 [▼
0 => "name"
1 => "oId"
]
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:20 [▼
"Oid" => 10401419
"Active" => true
"Speed" => "0"
"Weight" => "0"
"Act" => "0"
"Code" => ""
"Control" => false
"Type" => 1
"Max" => 1
"Name" => "Arl"
"Number" => "9-10"
"Mode" => 1
"Recipe" => ""
"Line" => "-1"
解决方案
推荐阅读
- java - StyleableProperty 需要什么才能真正监听 css 文件中的更改?
- python - Python多处理ForkingPickler问题
- r - R闪亮中的异步渲染顺序
- python - Plotly Heatmap 仅显示图像并保存
- python - dt.date 返回 AttributeError: Can only use .dt accessor with datetimelike values
- android - 当我尝试从 android 设备的内部存储中附加时,为什么 gmail 应用程序将 csv 或 doc 文件名重命名为五位数字?
- html - 如何将不同的css样式应用于同一页面上的两个不同的表单元素?
- c# - 尝试学习如何使用 Theadpool 生成网格数据
- python - Matplotlib 子图缺少网格
- javascript - 如何在不同路由的 html 上设置不同的溢出?