【发布时间】:2018-12-05 09:23:43
【问题描述】:
我有一个包含模型对象数组的集合对象,我想从模型中选择特定字段。
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\Model Object
[1] => App\Model Object
[2] => App\Model Object
)
)
现在我想从模型对象中选择一些字段。当我尝试执行以下语法时
print_r($collection->select('filed a', 'field b'));
然后出现以下错误。
Macroable.php 第 74 行中的 BadMethodCallException:方法选择确实如此 不存在。
我认为 select 可以直接与 eloquent 模型一起使用,但不能与集合一起使用。
【问题讨论】: