Eloquent select rows with empty string or null value

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.

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


Try using orWhereNull for the second clause:

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

Not sure, but this might work:

$user->albums()->where_in('col', array(NULL,''));

Need Your Help

How to get the last record per group in SQL

sql-server-2008 tsql sql-server-2005 greatest-n-per-group

I am facing a rather interesting problem. I have a table with the following structure:

Rails on Windows is so slow (rails -v takes 4 seconds)

ruby-on-rails ruby windows windows-vista

I'm using rails Version 3.0.3 and ruby Version 1.9.2p136 (2010-12-15) on a Intel Core 2 Duo 2,6 Ghz with 4 GB Ram and Windows Vista Business SP2 with no other (heavy) applications running. I have a...