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 Anonymous classes in PHP 7?

How to set up custom error pages in .htaccess for your Apache server (ErrorDocument)

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

Set PHP config Variables (like ini_set) with .htaccess

How to hide certain file types from directory listings

What is WordPress default Apache .htaccess rules?

How to get the type of a variable in JS?

What are Template literals (Template strings) in JS?

How to add a name prefix to all routes in a group?

When is __destruct called in PHP?