简体   繁体   中英

laravel whereJsonContains get rows with any value

Is it possible to get rows with any value is whereJsonContains? For example:

Shipments::query()
         ->where('status', Shipment::STATUS_PAID)
         ->whereJsonContains('config', ['id' => 5, 'category_id' => /* ANY NUMBER HERE */])
         ->get();

I would take a look at this: https://laravel.com/docs/8.x/queries#json-where-clauses

I am assuming that if you want to check any value is because category_id is a nullable field and you want to get the ones that are not null.

Shipments::query()
     ->where('status', Shipment::STATUS_PAID)
     ->whereJsonDoesntContain('config', ['id' => 5, 'category_id' => null])
     ->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