[英]How can I only pluck a column inside the `hasManyThrough` relationship in Laravel?
Building::with('user_through_building')
->where('id', $building_id)
->pluck('user_through_building.id');
我一直在收到错误Unknown column 'user_through_building.id' in 'field list' (SQL: select 'user_through_building'.'id' from 'buildings' where 'id' = 20 and 'buildings'.'deleted_at' is null)
试试这个
Building::with(['user_through_building' => function($q){
$q->pluck('id');
}])->where('id', $building_id)
// Retrieve all buildings that have at least one user_through_building
return Building::has('user_through_building')->get(['id']);
// Returns all Buildings, along with user_through_building' IDs
return Building::with('user_through_building:id')->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.