简体   繁体   English

如何覆盖 laravel 查询构建器对象中的 where 子句?

[英]How can I overwrite where clauses in laravel query builder object?

Example I have query builder object示例我有查询生成器对象

$queryBuilder = Products::where('price', '>', 100);

But if I need change where clauses to example - where('price', '<', 100).但是,如果我需要将 where 子句更改为示例 - where('price', '<', 100)。
How can I overwrite current where clauses in this object?如何覆盖此对象中的当前 where 子句? Is it has way?有办法吗?

Use Laravel conditional Clause使用 Laravel 条件子句

 ->when($yourCondition, function ($query) {
       $query->where('price', '>', 100);
  }, function ($query) {
       $query->where('price', '<', 100);
 })

https://laravel.com/docs/9.x/queries#conditional-clauses https://laravel.com/docs/9.x/queries#conditional-clauses

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM