我正在使用laravel eloquent从mongodb获取数据。
场景是,有3个字段:
字段\u 1是必需的,而字段\u 2和字段\u 3是可选的。
如果有字段\3,我需要在字段\3上应用where子句,如果有字段\2,where子句将在字段\2上应用,否则默认情况下,where子句将在字段\1上应用。
我只想用拉雷维尔的口才做以下几点:
if(field_3 is notNull){
-> where(field_3 = "something");
}
elseif(field_2 is notNull){
-> where(field_2 = "something");
}
else{
-> where(field_1 = "something");
}
我希望用SQL查询来实现这一点。
谢谢。