How to write Laravel eloquent query where (condition) and (condition2 or condition 3)

  eloquent, laravel, php, sql

Lets say we have SQL like this

select * from cards
where (deck_id=${deck_id})
and (added_by =${user_id} or is_available = 1)

And want to write in Laravel eloquent

I tried using the following queries but the result is not same as it suppose to be.

Card::where(['deck_id'=>$deck_id,'added_by'=>$user_id])
    ->orWhere(['deck_id'=>$deck_id,'is_available'=>1])
    ->get();

Card::where(['deck_id'=>$deck_id])
        ->Where(['added_by'=>$user_id])
        ->orWhere('is_available',1)
        ->get();

Source: Laravel

Leave a Reply