我想勇敢地获得所有地址ID,包括那些被丢弃的地址ID。这就是它的工作原理,但我也没有得到垃圾:
$clientIDs = Client::pluck('address_id')->all();
这是我已经尝试过的:
$clientIDs = Client::pluck('address_id')
->withTrashed()
->get();
投掷:
Method withTrashed does not exist.
如何使用 pluck 和 withTrashed() 来解决这个问题?
pluck()
已经完成查询并为您从数据库中检索信息。因此 ->all()
调用是多余的 - 它的作用是将 Eloquent 集合转换为数组。
因此,您在执行查询后调用
withTrashed()
。移动它们就可以了:
$clientIds = Client::withTrashed()->pluck('address_id'); // no need for ->get()