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 use subdomains as parameters in your routes (or in your web.php file)

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

How to increment a value in the database

How to add the default charset to UTF-8 in .htaccess

How to sort an array in javascript?

How could you include a custom function for every single time PHP runs?

How to hide certain file types from directory listings

How to disable file hotlinking in Apache with .htaccess

How to undelete a soft deleted Eloquent row?

How to generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?