【发布时间】:2016-06-23 17:17:25
【问题描述】:
我有一个 Eloquent 集合(已经执行了查询),我需要对这个数组中的两个项目做一些事情,所以我需要使用 only 或 pluck 方法,但它们不会返回我需要的...
$orders = Order::with('parts')->paginate(50);
$orders[0]->parts->lists('name'); // Returns names
$orders[0]->parts->lists('custom_name'); // Returns custom names
$orders[0]->parts->only(['name', 'custom_name']); // Returns nothing
$orders[0]->parts->pluck(['name', 'custom_name']); // Returns no values
【问题讨论】:
标签: eloquent laravel-5.2 laravel-collection