framework: Check if attribute is empty for whereNotIn on QueryBuilder

I use the whereNotIn function with a “dynamic” array, and this array may be empty. When the array is empty, SQL return a syntax error, because it is translated to a not in ().

It would be great if the whereNotIn function could check the emptiness of the array passed, and not translate anything to SQL if it is the case.

Ex:

    $array = array();
    DB::table('users')->whereNotIn('users.id', $array);

This will become

   SELECT * FROM users WHERE users.id NOT IN ();

And this throws a SQL syntax error.

(Edited for ex.)

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 1
  • Comments: 18 (13 by maintainers)

Most upvoted comments

👍 i regularly create workarounds for this

Well whereIn([]) should return an empty collection and whereNotIn([]) should just be ignored then (hence returning the query as usual). But a syntax error no, that’s very dangerous in production.