[英]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.