How to use laravel orWhere clause code answer – 2024

In this article, we will learn about how to use laravel orWhere

1). where like laravel

User::query()
   ->where('name', 'LIKE', "%{$searchTerm}%") 
   ->orWhere('email', 'LIKE', "%{$searchTerm}%") 
   ->get();

reference:
https://freek.dev/1182-searching-models-using-a-where-like-query-in-laravel

2). laravel orWhere

Source: laracasts.com

$camps = $field->camps()->where('status', 0)->where(function ($q) {
    $q->where('sex', Auth::user()->sex)->orWhere('sex', 0);
})->get();

3). laravel where like

Source: laravel.com

$users = DB::table('users')
                ->where('name', 'like', 'T%')
                ->get();

Discover more from STRUGGLER KING.COM

Subscribe now to keep reading and get access to the full archive.

Continue Reading