Convert.ToInt32
Convert.ToInt32

Reputation: 279

Wildcard-like syntax in an eloquent Where clause to search between two strings

I saw the answer provided in this question Wildcard-like syntax in an eloquent Where clause? now I want to know if is there a way to search between two strings?.

basicasicaly in my code I want to show requests that have a status of new or scheduled.

$requests = DB::table('requests')
        ->select('requestDate','requestTime','status','requestID')
        ->where('requestorID', '=',$userID)
        ->where('status', 'LIKE','%New%')
        ->get();

Upvotes: 0

Views: 514

Answers (3)

OMR
OMR

Reputation: 12188

you can use whereIn ,The whereIn method verifies that a given column's value is contained within the given array:

$requests = DB::table('requests')
        ->select('requestDate','requestTime','status','requestID')
        ->where('requestorID', '=',$userID)
        ->whereIn('status', ['new','scheduled'])
        ->get();

Upvotes: 2

Gert B.
Gert B.

Reputation: 2362

you can simply use a where with an orWhere:

$requests = DB::table('requests')
        ->select('requestDate','requestTime','status','requestID')
        ->where('requestorID', '=',$userID)
        ->where(function($q) {
          $q->where('status', 'LIKE','%New%');
          $q->orWhere('status', 'LIKE','%Scheduled%');
       
        })->get();

Upvotes: 0

knubbe
knubbe

Reputation: 1182

You can use:

->where('status', 'new')
->orWhere('status', 'scheduled')

Upvotes: 0

Related Questions