whereIntIn() / orWhereIntIn()
Type-safe WHERE IN condition that only accepts integer values.
Signature
whereIntIn(string $column, array $values): self
orWhereIntIn(string $column, array $values): self
Basic usage
Use whereIntIn() when you want to filter by a list of integer IDs or values.
Every value in the array is validated – if any value is not a valid integer,
the entire query is rejected.
// Step by step
$db->whereIntIn('id', [1, 2, 3]);
$users = $db->get('users');
// Fluent
$users = $db->whereIntIn('id', [1, 2, 3])->get('users');
// → SELECT * FROM users WHERE id IN (1, 2, 3)
Combined with other conditions
// Step by step
$db->whereIntIn('category_id', [10, 20, 30]);
$db->whereInt('active', 1);
$products = $db->get('products');
// Fluent
$products = $db->whereIntIn('category_id', [10, 20, 30])
->whereInt('active', 1)
->get('products');
// → SELECT * FROM products
// WHERE category_id IN (10, 20, 30) AND active = 1
Using orWhereIntIn()
// Step by step
$db->whereIntIn('role_id', [1, 2]);
$db->orWhereIntIn('group_id', [10, 11]);
$rows = $db->get('users');
// Fluent
$rows = $db->whereIntIn('role_id', [1, 2])
->orWhereIntIn('group_id', [10, 11])
->get('users');
// → SELECT * FROM users
// WHERE role_id IN (1, 2) OR group_id IN (10, 11)
Practical example – filter by user selection
A common scenario: the user selects items in a list and you need to fetch
only those records. whereIntIn() is the safe way to do this:
// IDs from a form or checkbox selection
$selectedIds = [4, 7, 12, 19];
// Step by step
$db->whereIntIn('id', $selectedIds);
$db->whereInt('active', 1);
$items = $db->get('orders');
// Fluent
$items = $db->whereIntIn('id', $selectedIds)
->whereInt('active', 1)
->get('orders');
// → SELECT * FROM orders WHERE id IN (4, 7, 12, 19) AND active = 1
Validation & error handling
Every value in the array must be an integer or a numeric string like '42'.
The array must not be empty. Any violation throws an InvalidArgumentException.
try {
// ❌ Mixed types – 'abc' is not a valid integer
$db->whereIntIn('id', [1, 2, 'abc']);
$rows = $db->get('users');
} catch (\InvalidArgumentException $e) {
echo $e->getMessage();
// → Non-integer value detected in whereIntIn(): 'abc'
}
try {
// ❌ Empty array not allowed
$db->whereIntIn('id', []);
$rows = $db->get('users');
} catch (\InvalidArgumentException $e) {
echo $e->getMessage();
// → Empty array passed to whereIntIn()
}
See also
- whereIn() – WHERE IN for any scalar values
- whereInt() – single integer condition