not()
The not()
helper is used to safely invert values or subqueries in WHERE conditions. Internally this wraps the value with a NOT (...)
expression.
Especially useful with methods like whereIn()
, whereBool()
or when working with subqueries.
Signature:
public function not(mixed $value): string
Example: Invert a boolean condition
// WHERE NOT (is_active = 1)
$db->where('is_active', $db->not(1));
$users = $db->get('test_users');
Example: NOT IN (subquery)
// WHERE id NOT IN (SELECT user_id FROM banned_users)
$sub = $db->subQuery();
$sub->select('user_id')->from('banned_users');
$db->whereIn('id', $db->not($sub));
$users = $db->get('test_users');
Note: The
not()
method wraps the given value or subquery in a NOT (...)
expression. Be careful when using it with unescaped strings or raw SQL – always validate your input or use safe helpers like whereInt()
or whereIn()
.