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 redirect your website to a new domain/location in .htaccess

How to increment a value in the database

How to block an IP address in .htaccess

How to add and remove items to an array in JS?

How to manually write your own pagination in PHP

Force trailing slash (redirect if no trailing slash exists) in .htaccess

How to get the first row that matches some where queries, or create it if it doesn't exist (in Laravel's Eloquent)?

How to check if a string contains a certain substring?

How to find the average value of items in a Laravel Collection?

How to return an item in Eloquent, or throw a ModelNotFoundException exception if it isn't found?