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
webdevetc

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.



More...


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 find out what version of Laravel you are using?

How to access the Laravel's route parameters outside of the controller?

What does PEAR stand for?

How to eager load multiple levels of relationships in Eloquent?

How to exclude URLs from the Laravel CSRF protection?

How to block access to certain referrers in Apache using .htaccess

How to provide a default model object for relationships?

How to increment a value in the database

How can you check if a variable is alphanum (alphanumeric, letters and numbers only) in PHP?

How to review blog posts (written by other users) before they get published on your WordPress blog?