Reputation: 2848
SELECT
SUM(username = 'benjamin') as c1,
SUM(email = '[email protected]') as c2
FROM users WHERE active = 0
I have a mysql query need to check 2 columns match
But now I need to write it into Laravel Eloquent
anyone know how to do this in Eloquent?
Upvotes: 1
Views: 2387
Reputation: 13709
You can do it like this:
User::where('active', 0)
->select(DB::raw("SUM(username = 'benjamin') as c1, SUM(email = '[email protected]') as c2"))
->get();
Hope this helps!
Upvotes: 2