In Laravel 11, you can use the `orWhere()` clause to filter records based on multiple conditions where at least one condition must be true.
1. Basic `orWhere()` Query in Eloquent
$users = User::where('status', 'active') ->orWhere('role', 'admin') ->get();
Retrieves users where `status = active` OR `role = admin`.
2. Using `orWhere()` with Multiple Conditions
$users = User::where('status', 'active') ->orWhere('role', 'admin') ->orWhere('email_verified_at', '!=', null) ->get();
Retrieves users who are active, admins, OR have verified emails.
3. Using `orWhere()` with Comparisons (`>`, `<`, `!=`)
$users = User::where('age', '>', 30) ->orWhere('membership', 'premium') ->get();
Retrieves users who are older than 30 OR have a premium membership.
4. Using `orWhere()` with `where()`
$users = User::where('status', 'active') ->where('country', 'India') ->orWhere('role', 'admin') ->get();
Retrieves users who are active and from India OR admins from any country.
5. Using `orWhere()` with LIKE (Pattern Matching)
$users = User::where('name', 'LIKE', 'John%') ->orWhere('email', 'LIKE', '%@gmail.com') ->get();
Retrieves users whose name starts with “John” OR have a Gmail account.
6. Using `orWhere()` with AND Conditions (`where + orWhere`)
$users = User::where('status', 'active') ->where(function ($query) { $query->where('role', 'admin') ->orWhere('role', 'editor'); }) ->get();
Retrieves active users who are either admins OR editors.
7. Using `orWhere()` with Raw SQL Expressions
$users = User::whereRaw('YEAR(created_at) = ?', [2024]) ->orWhereRaw('LENGTH(name) > ?', [5]) ->get();
Retrieves users created in 2024 OR whose name length is greater than 5.