如何比较2个雄辩的集合,并从另一个集合中删除什么? [英] How do I compare 2 eloquent collections and remove whats in one from the other?

查看:23
本文介绍了如何比较2个雄辩的集合,并从另一个集合中删除什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有所有门的集合以及当前用户可以访问的门的集合.如何比较两者并从所有门集合中删除用户已经可以访问的门?

I have a collection of all doors, and a collection of doors that the current user has access to. How can I compare the two and remove from the all doors collection the doors the user already has access to?

$doors = Door::orderBy('name', 'asc')->get();
$users_doors = $user->doors;

这是两个集合.

推荐答案

使用 Collection:: diff() :

$doorsWithAccess = $doors->diff($users_doors);

这篇关于如何比较2个雄辩的集合,并从另一个集合中删除什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆