记录下 Laravel 框架数据库查询构造器中 when 的一次错误用法。前车之鉴,后车之师。

错误用法:

->when(!empty($openid),function($query,$openid){
                    return $query->where('openid',$openid);
                }

正确用法1:

->when($openid,function($query,$openid){
                    return $query->where('openid',$openid);
                }

正确用法2:

->when($openid,function($query) use($openid){
                    return $query->where('openid',$openid);
                }

Enjoy it !

相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-11-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
相关资源
相似解决方案