将 SQL 查询转换为 Laravel 查询生成器

Convert SQL query into Laravel query builder

我需要将此查询转换为 laravel 查询生成器

select * from employee where(( age = 25 and salary = 20000) or (age =30 and salary = 30000))

你能试试这个吗,

$data = Model::where([["age", "25"],["salary", "20000"]])
    ->orWhere([["age", "30"],["salary", "30000"]])
    ->get();

如果你想对 where 子句进行分组,你可以将它们嵌套在闭包中:

DB::table('employee')
    ->where(function ($query) {
        $query->where('age', 25)->where('salary', 20000);
    })
    ->orWHere(function ($query) {
        $query->where('age', 30)->where('salary', 30000);
    })
    ->get();

有关详细信息,请查看文档中的 Parameter Grouping