1

In laravel elequent query how to make these two where select in one.

I also feels if there too many conditions, I've too use too many where clause.

->where('trade_status', '<>', 'TRADE_FINISHED')
->where('trade_status', '<>', 'TRADE_SUCCESS')
LF00
  • 27,015
  • 29
  • 156
  • 295

2 Answers2

2

Use whereNotIn():

->whereNotIn('trade_status', ['TRADE_FINISHED', 'TRADE_SUCCESS']);
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
1

Here in documentation you can notice

You can pass array of condition like

$users = DB::table('users')->where([
    ['status', '=', '1'],
    ['subscribed', '<>', '1'],
])->get();

for your condition it should be like

 DB::table('your_table')->where([
    ['trade_status', '<>', 'TRADE_FINISHED'],
    ['trade_status', '<>', 'TRADE_SUCCESS'],
])->get();
Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105