This page looks best with JavaScript enabled

How to Get List of User by List of Email Using Eloquent Query in Laravel

 ·  ☕ 1 min read  ·  ✍️ shibu

user Laravel eloquent, we can select all users from arrays of emails.

I made a cart application. Where I required to get list of users from list of emails(order emails).

Using whereIn eloquent method we can easily fetch array of users from database.

1
2
User::whereIn('email', ['polodev10@gmail.com', 'company@gmail.com', 'milky@gmail.com'])
->get();

In my case, I required to fetch, array of user ids. Using pluck method I was able to do that

1
2
User::whereIn('email', ['polodev10@gmail.com', 'company@gmail.com', 'milky@gmail.com'])
->pluck('id')->all();
Share on

Shibu Deb Polo
WRITTEN BY
shibu
Web Developer