简体   繁体   中英

How use use multi compare with one where() in laravel eloquent query?

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')

使用whereNotIn()

->whereNotIn('trade_status', ['TRADE_FINISHED', 'TRADE_SUCCESS']);

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM