mysql - Laravel 从查询中检索列值给出错误

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

最佳答案

你可以做一个

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

我想上面应该可以。

关于mysql - Laravel 从查询中检索列值给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50126300/

相关文章:

php - 如何从集合内的数组中忽略或删除空元素

mysql - PHP 从 7.1 切换到 7.2 后允许的内存大小耗尽

mysql - 如何从不同的表中计算laravel

controller - 从 grails Controller 获取请求 URL

arrays - 如何用groovy语言将项目一一添加到数组中

php - MySQL 中的唯一标识符

python 导入 MySQLdb

php - 如何撤消命令 "php artisan config:cache"的影响?

c# - 通过数据网格将数据保存到数据库

mysql - 欢笑中的数据库到数据库的复制