Php 我怎么能只在拉威尔的“hasManyThrough”关系中挑出一个专栏呢?
“字段列表”中的未知列“user\u through\u building.id”(SQL:选择“user\u through\u building”。“id”来自'buildings',其中'id'=20和'buildings'。“deleted\u at'为空)试试这个Php 我怎么能只在拉威尔的“hasManyThrough”关系中挑出一个专栏呢?,php,laravel,Php,Laravel,“字段列表”中的未知列“user\u through\u building.id”(SQL:选择“user\u through\u building”。“id”来自'buildings',其中'id'=20和'buildings'。“deleted\u at'为空)试试这个 Building::with('user_through_building') ->where('id', $building_id)
Building::with('user_through_building')
->where('id', $building_id)
->pluck('user_through_building.id');
试试这个
Building::with('user_through_building')
->where('id', $building_id)
->pluck('user_through_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();