php - 我怎样才能只在 Laravel 的“hasManyThrough”关系中提取一列?
问题描述
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)
解决方案
// 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();
推荐阅读
- java - How to mock a method in Java, if that method present in external jar?
- node.js - Azure function response status code is always 200
- java - The library com.google.android.gms:play-services-basement is being requested
- r - Shiny 中 SelectInput 的“动态”选择
- flutter - where does the stack widget make its entry in flutter for the following case
- javascript - 我在 asp.net mvc 中为我的购物车使用简单的购物车 js
- javascript - 如何使用javascript检查剑道网格是否包含特定项目
- javascript - 无法在 React 中访问窗口变量
- python - router registration order influences output
- python-3.x - Why is it necessary to create a conda environment for Tensorflow during installation? Why can't we install Tensorflow through pip?