PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

[FIXED] Laravel / Eloquent whereIn with null

 February 10, 2022     eloquent, laravel-5.3     No comments   

Issue

How do I apply Laravel's Eloquent whereIn() so that it includes null?

I've tried:

User::whereIn("column", [null, 1, 2]) -> get();

And

User::whereIn("column", [DB::raw("null"), 1, 2]) -> get();

But both queries return no results.

Thanks!


Solution

I don't think you can pass null in in mysql statement. If you run the query in mysql console it will skip the null.

Try User::whereNull('column')->orWhereIn('column', array(1, 2))->get();



Answered By - Saumini Navaratnam
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing