Laravel 5.4 查询生成器使用 orWhere 子句时缺少参数 2

Laravel 5.4 query builder Missing argument 2 when using orWhere clause

谁能告诉我为什么我会收到此错误以及如何修复它。

    $lastDayPreviousMonth = date("Y-m-d", strtotime("last day of previous month"));
    $firstDayPreviousMonth = date("Y-m-d", strtotime("first day of previous month"));

    $query = DB::table('employees')
        ->where('Emp_ClientId', '=', $clientId)
        ->where('Emp_StatusId', 1)
        ->orWhere(function ($query, $firstDayPreviousMonth, $lastDayPreviousMonth){
            $query->where('Emp_DateSuspTerm', '>=', $firstDayPreviousMonth)
                ->where('Emp_DateSuspTerm', '<=', $lastDayPreviousMonth)
                ->where('Emp_ClientId', '=', $clientId);
        })
        ->count();

当我 运行 this

时出现以下错误

App\Http\Models\Employees::App\Http\Models{closure}()

缺少参数 2

我认为这与传递给 orWhere 子句的 firstdaypreviousmonth 和 lastdaypreviousmonth 参数有关 - 如果我将其取出,我会得到未定义的变量。

您可以使用 use 关键字来使用闭包

$query = DB::table('employees')
            ->where('Emp_ClientId', '=', $clientId)
            ->where('Emp_StatusId', 1)
            ->orWhere(function ($query) use($firstDayPreviousMonth, $lastDayPreviousMonth,$clientId){
                $query->where('Emp_DateSuspTerm', '>=', $firstDayPreviousMonth)
                    ->where('Emp_DateSuspTerm', '<=', $lastDayPreviousMonth)
                    ->where('Emp_ClientId', '=', $clientId);
            })
            ->count();