Replace Multiple where Conditions with whereAll() in Laravel

Apply the same condition across multiple columns without repeating yourself.

  • 29 Jun, 2026
  • 27 Views

Replace Multiple where Conditions with whereAll() in Laravel

Many developers write:

Product::where('title', 'like', "%Laravel%")
    ->where('description', 'like', "%Laravel%")
    ->where('tags', 'like', "%Laravel%")
    ->get();

It works...

But repeating the same condition makes queries longer than necessary.


The Cleaner Solution

Laravel provides:

whereAll()

Example:

Product::whereAll(
    ['title', 'description', 'tags'],
    'like',
    '%Laravel%'
)->get();

Laravel automatically applies the condition to every column.

Real Project Example

Suppose you're building a document search where the keyword must exist in every searchable field.

Document::whereAll(
    ['title', 'summary', 'content'],
    'like',
    "%{$keyword}%"
)->get();

Only documents containing the keyword in all three fields will be returned.

Share: