Laravel AND,多个OR口才查询无法按预期工作

时间:2017-02-21 11:27:33

标签: php mysql laravel laravel-5.3

查询:

Need::Where('student_id', '!=', $id)->Where($matchto)->orWhere($matchfrom)->orWhere($matchstandard)->orWhere($matchlives_in)->orWhere($matchhobbies)->orWhere($matchskills)->orWhere($matchspecialization_1)->orWhere($matchdesignation_1)->get();

它像这样生成结果查询

"query" => "select * from `needs` where `student_id` != ? and (`to` = ?) or (`from` = ?) or (`standard` = ?) or (`lives_in` = ?) or (`hobbies` = ?) or (`skills` = ?) or (`specialization_1` = ?) or (`designation_1` = ?)"

我想要的是

"query" => "select * from `needs` where `student_id` != ? and **(**(`to` = ?) or (`from` = ?) or (`standard` = ?) or (`lives_in` = ?) or (`hobbies` = ?) or (`skills` = ?) or (`specialization_1` = ?) or (`designation_1` = ?)**)**"

student_id`之后的额外括号!=?和。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

你需要筑巢你的条件:

MSR->Temp->Export_1->ZipExport_1->ZipExport1