雄辩的选择行,其中包含空字符串或空值 [英] Eloquent select rows with empty string or null value

查看:52
本文介绍了雄辩的选择行,其中包含空字符串或空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似 $ user-> albums()-> where('col',NULL)的东西,它工作正常,然后我尝试使用将其扩展为空字符串$ user-> albums()-> where('col',NULL)-> or_where('col',''),并且无法正常工作.

I have something like $user->albums()->where('col', NULL), it works fine then I tried to extend it to empty strings with $user->albums()->where('col', NULL)->or_where('col', '') and it's not working.

我还看到在该帖子上我可以使用 where_null('col'),但是它不起作用,并且它没有记录.任何简单的方法来选择空或NULL col

Also I saw on this post that I could use where_null('col') but it's not working and it's not documented. Any simple method to select where empty or NULL col

推荐答案

尝试使用 orWhereNull :

$users = DB::table('users')
        ->where('col', '=', '')
        ->orWhereNull('col')
        ->get();

这篇关于雄辩的选择行,其中包含空字符串或空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆