A list of operators on Eloquent's where() method

Laravel: A list of operators on Eloquent's where() method

When you use Eloquent's where() method, by default it will use the = operator (i.e. ->where('fieldname','value') will generate ... WHERE `fieldname` = 'value'....

However you are not limited to just =. You can do something like this:

  1. $posts = Post::where("id","!=",123)->get()

Any of the following may be used as the second parameter (and use the third param for the value)

=, <, >, <=, >=, <>, !=, LIKE, NOT LIKE, BETWEEN, ILIKE

(ILIKE = case insensitive like, I believe this is just for Postgre)

webdevetc profile pic

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.


Comments and discussion about A list of operators on Eloquent's where() method

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Laravel language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to set environmental variables in your .htaccess file

What are the SPL data structures

How does PHP compare objects?

What are generators in PHP, and how do they compare to arrays?

How do you launch the PHP interactive shell?

How do you access the php://input stream?

301 Redirect a single URL in .htaccess to a new location

How to find the intersection (same values) from two arrays?

How to install and use jpegoptim on Linux CentOS

How to provide a default model object for relationships?