Search code examples
mysqllaraveleloquentphp-7

How to apply 'UPPER' to Eloquent query?


How do I do this in Laravel's Eloquent?

I want my sql output to be this:

SELECT * FROM users UPPER(email) LIKE UPPER("%email%").

Here is the code I'm trying to modify:

$users = User::where('email', 'like', '%'.request('email').'%')->paginate(50);

I tried doing this but it didn't work:

$users = User::where('UPPER(email)', 'like', 'UPPER("%'.request('email').'%")')->paginate(50);

Solution

  • using where Raw maybe?

    User::whereRaw('UPPER(`email`) LIKE ? ',[trim(strtoupper($email)).'%'])->paginate(15);
    

    This post looks like what you are trying to do.

    https://stackoverflow.com/a/46238839/13468924