Building::with('user_through_building')
->where('id', $building_id)
->pluck('user_through_building.id');
I'm keep getting error 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)
Try this one
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.