Laravel从查询中检索列值会产生错误

时间:2018-05-02 02:21:56

标签: mysql laravel controller

我目前正在处理一个学校项目,并且正在尝试从成功运行的查询中检索值。查询如下:

$airportQuery = Airport::where('id', '=', $airport)->get(); //Returns all columns of users selected airportId

我正在尝试检索列“extendedcenterlineLong”和“extendedcenterlineLat”。我是通过运行

来做到这一点的
array[] = $airportQuery->extendedcenterLong;
array[] = $airportQuery->extendedcenterLat;

(数组也没有命名为array [])当我尝试运行myQuery时出现此错误 enter image description here

我无法解决这个问题,我做错了什么? 非常感谢!

编辑:我也有这些查询来获取用户选择的上一行或下一行

$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时,有两个项目是列信息的数组彼此相同,基本上是副本。

1 个答案:

答案 0 :(得分:2)

你可以做一个

$airportQuery = Airport::where('id', '=', $airport)->first();

我猜以上应该有用。