【发布时间】:2020-01-16 20:43:58
【问题描述】:
是否可以在不循环所有结果的情况下查询表并显示某些列?
所以,我有这个问题
$shipping = Preferences::where('preferences_id', '=', 1)->get();
现在我正在尝试获取这些列
$shipping->option_one
$shipping->option_two
错误很明显
未定义属性:Illuminate\Database\Eloquent\Collection::$preferences_option_one
未定义属性:Illuminate\Database\Eloquent\Collection::$preferences_option_two
我该怎么做?
print_r($shipping)
Array
(
[0] => stdClass Object
(
[preferences_id] => 1
[preferences_option_one] => Priority Mail
[preferences_option_two] => Express Mail
)
)
1
错误:
[2017-05-30 10:06:10] production.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Uncaught TypeError: 传递给 Illuminate\Exception\WhoopsDisplayer::display() 的参数 1 必须是一个实例异常的,给定的 TypeError 实例,在第 281 行的 /var/www/html/vendor/laravel/framework/src/Illuminate/Exception/Handler.php 中调用并在 /var/www/html/vendor/laravel/framework 中定义/src/Illuminate/Exception/WhoopsDisplayer.php:43
/var/www/html/vendor/laravel/framework/src/Illuminate/Exception/Handler.php第281行
protected function displayException($exception)
{
$displayer = $this->debug ? $this->debugDisplayer : $this->plainDisplayer;
return $displayer->display($exception); <--- line 281
}
/var/www/html/vendor/laravel/framework/src/Illuminate/Exception/WhoopsDisplayer.php:43
public function display(Exception $exception) <-- line 43
{
$status = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$headers = $exception instanceof HttpExceptionInterface ? $exception->getHeaders() : array();
return new Response($this->whoops->handleException($exception), $status, $headers);
}
【问题讨论】:
标签: php laravel laravel-4.2