2017-06-06 85 views
1

匹配2雄辩收集的ID我有这样的数据库:去除Laravel

item: id 
item_propiety_list: id 
found_item_propieties: item_id, item_propiety_list_id 

所以每个$item我得到的found_item_propieties的集合。如果找不到这样的propieties,没有什么是存储在found_item_propieties

我想要得到的NOT FOUNDitem_propiety_list雄辩的集合。

我已经这样做了SQL,但肯定有办法在Eloquent中做到这一点。

有什么建议吗?

+0

如果你只是想要一个集合,云的使用'收集($东西)'。 –

回答

1

您可以使用where()收集方法。如果它是一个标准的口才集合,这应该工作:

$notFound = $collection->where('found_item_properties', null); 

更新

可以filter()使用:

$notFound = $collection->filter(function($i) { 
    return empty($i->found_item_properties); 
}); 
+0

毫无疑问,这是我的错。如果找不到,则不会创建条目。我只有在数据库中找到的条目,并且需要找到未找到的条目。 – prgrm

+0

@prgrm我已经更新了答案。 –