O'Reilly logo

Learning Laravel's Eloquent by Francesco Malatesta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

where, aggregates, and other utilities

No doubt that the where() method will be one of your best friends while building queries and selecting records in your work with Eloquent. Don't you think it would be worth taking a look at it in detail?

Let's recap what we already know.

You can use the where() method to filter results. The correct syntax you have to use is this:

  where('field_name', 'operator', 'term')

So, for example, you can filter all the books with less than 100 pages with

  where('pages_count', '<', 100)

Also, you can chain more where methods, one after another, to build more complex queries. Let's select all those books that have less than 100 pages, with a title that starts with an M.

 where('pages_count', '<', 100)->where('title', 'LIKE', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required