DEV Community

Gurpreet Kait
Gurpreet Kait

Posted on • Originally published at larachamp.com on

1

WhereAll and WhereAny In Laravel 10.47 Update

Today I’m going to share an update of the Laravel 10.47 version in which we have two new Laravel Eloquent methods that make conditions easier to write most of the time in case of searching for something. We going to see how we can use these methods.

Before explaining the methods I’m gonna show you that If I use the search input box in my laravel app to search for something in DB. It can be by name, email, age, etc. I used to do something as mentioned below in the code.

// a simple search query 
$orders->where('email', 'like', "%$search%")->where('name','like',"%$search%");
Enter fullscreen mode Exit fullscreen mode

But now you can enjoy this new method called whereAll instead.

WhereAll Method

This method can replace this whole line of code and can act easily in one syntax as mentioned in the below code.

// syntax
whereAll($columns, $operator = null, $value = null, $boolean = 'and')

//Usage
$orders->whereAll(['email','name'],'like',"%$search%");

//Query
select * from "orders" where (name like "shantu" AND email like "shantu")
Enter fullscreen mode Exit fullscreen mode

WhereAny Method

whereAny() method adds or instead of and expression in a query.

// syntax
whereANy($columns, $operator = null, $value = null, $boolean = 'and')

//Usage
$orders->whereAny(['email','name'],'like',"%$search%");

//Query
select * from "orders" where (name like "shantu" OR email like "shantu")
Enter fullscreen mode Exit fullscreen mode

I’m gonna link the original commit here Add whereAll and whereAny methods to the query builder

I hope you find this update helpful.

The post WhereAll and WhereAny In Laravel 10.47 Update appeared first on Larachamp.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay