Jijin P
Jijin P

Reputation: 268

How to use multiple where conditions in Laravel Eloquent?

This Query is working

    $conditions = [
        'status' => '1',
        'country' => "DK"
    ];
        $offers = Offers::where($conditions)->get();

How can i use LIKE %% in this

When i tried this in single condition , its working

      $offers = Offers::where('country' , 'LIKE' , '%DK%')->get();

Upvotes: 1

Views: 1557

Answers (2)

Marco Aurélio Deleu
Marco Aurélio Deleu

Reputation: 4367

Did you try this?

$conditions = [
    'status' => '1',
    'country' => "DK"
];
$offers = Offers::where('country' , 'LIKE' , '%DK%')->where($conditions)->get();

You can chain your where clauses as much as you want.

Upvotes: 4

Milos Sretin
Milos Sretin

Reputation: 1748

Actually you can use where multiple times so you can try something like:

$offers = Offers::where('country' , 'LIKE' , '%DK%')
    ->where('status', 1)
    ->get();

I didn't test this but you can try also like this: ( It might work but I'm note sure )

$conditions = [
    'status' => '1',
    'country' => "LIKE %DK%"
];
$offers = Offers::where($conditions)->get();

Upvotes: 0

Related Questions