使用Eloquent ORM,是否有来自SQL的等效MINUS操作?
例如
$ model1 = Model :: where('some constraints applied')$ model2 = Model :: where('some constraints applied')
我想得到$ model1中存在的所有模型,但不是$ model2中的模型
seblaze的答案看起来不错,但它会运行3个查询.另一个选项是Collection对象的diff()方法:
$result = $model1->diff($model2);
Run Code Online (Sandbox Code Playgroud)
这可以在从具有2个查询的数据库中获取数据之后起作用,但是完整的数据集(除非根据您的"约束应用"而有更多数据).