Support the ongoing development of Laravel.io →
Database Eloquent

I would simply like to run such query:

select * from `users` where SUBSTRING_INDEX(`email`, '@' ,-1) not in ('gmail.com, outlook.com');
Two ways crossed my mind which non of them work:

1

$providers = array('gmail.com', 'outlook.com');

$providers = "'" . implode("', '", $providers) . "'";

User::whereRaw("SUBSTRING_INDEX(`email`, '@' ,-1) not in (?)", $providers);

the above would not work because PDO will escape the "'" characters.

2

User::whereIn(DB::raw("SUBSTRING_INDEX(`email`, '@' ,-1)", $providers);

this one simply does not work. any idea?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ammont ammont Joined 10 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.