我可以运行以下代码来检查数据透视表中是否存在单行
if($person->comments()->where('comment_id', 1)->exists()) == 1){
//Do something
}
但是我如何检查行列表是否存在?
简单来说,我想说“如果数据透视表中的comment_ids行的id为1,2,3,4,5”。
这就是我到目前为止所得到的。
if(($person->comments()->where('comment_id', 1)->where('comment_id', 2)->where('comment_id', 3)->where('comment_id', 4)->where('comment_id', 5)->exists()) == 1){
//Do something
}
最佳答案
您可以数一下有多少个,例如:
$lookFor = [1,2,3,4];
if($person->comments()->whereIn('comment_id', $lookFor)->count() == count($lookFor)) {
}
关于php - 检查 Laravel 数据透视表中是否存在多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48386846/