我需要一些有关以下主题的建议和帮助。
我有一个像这样的迁移设置。
+--------------------+----------------------+--------------------+
| plates | plates_container | container_slots |
+--------------------+----------------------+--------------------+
| id | id | id |
| plate_container_id | number_of_slots(int) | slot |
| container_slot_id | | occupied (boolean) |
| | | plate_container_id |
+--------------------+----------------------+--------------------+
表之间的关系是这样的。
板
belongsTo
一个platecontainer
belongsTo
containerslot
PlateContainer
hasMany
containerSlots
hasMany
plates
ContainerSlot
belongsTo
plateContainer
hasOne
plate
我如何(由id
指定)获取所有number_of_slots
并检查哪些广告位已经occupied
哪些广告位已经slots = [
1 => false,
2 => false,
3 => true,
4 => false
//etc
];
。
所以要澄清一点。像这样或类似的列表是我要求的。
occupied
如果您对数据库结构有任何其他建议,请在评论中告诉我。在用户为slot
选择plate
后,每次更新 my_analyzer:
type: custom
tokenizer: keyword
filter: lowercase
products_filter:
type: "nested"
properties:
filter_name: {"type" : "string", analyzer: "my_analyzer"}
filter_value: {"type" : "string" , analyzer: "my_analyzer"}
属性时,我都有点怀疑。
答案 0 :(得分:1)
Eloquent's collection methods和pluck
会对您有所帮助。假设您已为每个提到的表正确定义了模型,您可以这样做:
PlateContainer::find($id)
->container_slots
->pluck('occupied', 'id');
这将以下面的形式(基本上是一个数组)为您提供所需的预期结果:
=> Illuminate\Database\Eloquent\Collection {#1859
all: [
1 => true,
2 => true,
3 => false,
4 => true
],
}