🎉🎉 Larasense is officially launched 🎉🎉
- Your Hub for Laravel News, Trends & Updates

Laravel where LIKE queries, before & after Laravel 11/12

laravel
tutorial
queries
Nabil Hassen
Nabil Hassen
Sep 26, 2025
Laravel where LIKE queries, before & after Laravel 11/12
Last updated on Sep 26, 2025
Table of contents:

Where LIKE Queries in Laravel

When working with databases in Laravel, one of the most common needs is to search for records using the SQL LIKE clause. This lets you perform partial matches—for example, finding all users whose names start with "John".

In this post, we’ll explore how to use where like queries in Laravel, how it worked before Laravel 11 & 12, and what changed in these newer versions. We’ll also cover case-insensitive LIKE queries, multiple-column LIKE queries, and the newer whereAny / whereAll / whereNone clauses.

Using LIKE in Laravel Before Versions 11 & 12

Before Laravel 11 and 12, you had to use the where method with the LIKE operator manually:

// Find users whose names start with "John"
$users = User::where('name', 'LIKE', 'John%')->get();
 
// Find users whose email contains "gmail"
$users = User::where('email', 'LIKE', '%gmail%')->get();

Using whereLike in Laravel 11 & 12

From Laravel 11 and 12, Eloquent introduced a more expressive whereLike and orWhereLike syntax:

// Find users whose names start with "John"
$users = User::whereLike('name', 'John%')->get();
 
// Find users whose email contains "gmail"
$users = User::whereLike('email', '%gmail%')->get();

Case Insensitive LIKE Queries

Whether LIKE queries are case-sensitive depends on the database collation. For example, MySQL’s utf8mb4_unicode_ci collation is case-insensitive by default.

If you want to explicitly force case-insensitive like queries, you can use LOWER():

// Case insensitive search for "john"
$users = User::whereRaw('LOWER(name) LIKE ?', ['%john%'])->get();

Or combine it with the new whereLike:

$users = User::whereLike(DB::raw('LOWER(name)'), '%john%')->get();

Multiple Columns LIKE Queries

Sometimes you want to search across multiple columns, such as name or email.

Before Laravel 11 & 12:

$users = User::where('name', 'LIKE', '%john%')
->orWhere('email', 'LIKE', '%john%')
->get();

From Laravel 11 & 12 onward:

$users = User::whereAny(['name', 'email'], 'LIKE', '%john%')->get();
 
$users = User::whereAll(['name', 'email'], 'LIKE', '%john%')->get();

Summary

  • Before Laravel 11 & 12: Use where('column', 'LIKE', 'pattern').
  • Laravel 11 & 12+: Use whereLike and orWhereLike for cleaner syntax.
  • Case Insensitive: Use LOWER() with raw queries if collation isn’t case-insensitive.
  • Multiple Columns: Use whereLike(['col1', 'col2'], 'pattern').
  • Advanced: Use whereAny, whereAll, and whereNone for multi-column LIKE queries with OR, AND, or NOT logic.
Nabil Hassen
Nabil Hassen
Full Stack Web Developer

Stay Updated.

I'll you email you as soon as new, fresh content is published.

Thanks for subscribing to my blog.

Latest Posts