我目前正在开展一个学校项目,并试图从成功运行的查询中检索值。查询是这样的:
$airportQuery = Airport::where('id', '=', $airport)->get(); //Returns all columns of users selected airportId
我正在尝试检索列“extendedcenterlineLong”和“extendedcenterlineLat”。我正在通过运行
array[] = $airportQuery->extendedcenterLong;
array[] = $airportQuery->extendedcenterLat;
(该数组也未命名为 array[])当我尝试运行 myQuery 时出现此错误
我没能解决这个问题,我做错了什么? 非常感谢!
编辑:我也有这些查询来从用户选择的内容中获取上一行或下一行
$previous = Airport::where('id', '<', $airport)->max('id'); //Returns the previous rows values from users current selected airportId
$next = Airport::where('id', '>', $airport)->min('id'); //Returns the next rows values from users current selected airportId
编辑:我通过执行 $airportQuery->first()->column_name
解决了这个问题。出于某种原因,当我打印出 $airportQuery 时,有两个项目是列信息的数组,它们彼此相同,基本上是一个副本。
最佳答案
你可以做一个
$airportQuery = Airport::where('id', '=', $airport)->first();
我想上面应该可以。
关于mysql - Laravel 从查询中检索列值给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50126300/