Laravel whereIn 与子查询的多列

Laravel multiple columns for whereIn with subquery

在 MySQL 中,要在 "WHERE IN" 子句中搜索多个列,通常按以下方式进行:

where (column1, column2) in (select column1, column2 from table)

我试图在 Laravel 中获得与此相同的结果,并尝试做类似的事情:

->whereIn(['column1', 'column2'], function($query){
            $query->select('column1', 'column2')
            ->from('table');
        })

我如何才能在 Laravel 上做与 MySQL 相同的事情?

您可以像这样使用 DB::raw 来实现:

->whereIn(DB::raw('(`column1`, `column2`)'), function($query){
        $query->select('column1', 'column2')
        ->from('table');
    })