我该如何只在Laravel中的“ hasManyThrough”关系中选择一列?

时间:2018-09-01 12:40:08

标签: php 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)

2 个答案:

答案 0 :(得分:1)

尝试这个

jsonString.replace(/"\s*:\s*"[^"]/g, match => {
  return match.slice(0, -1) + match[match.length - 1].toUpperCase()
})

答案 1 :(得分:1)

// 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();