laravel/framework · error · InvalidArgumentException

Invalid binding type

Error message

Invalid binding type: {$type}.

What it means

setBindings() replaces the bindings for one named slot. The slots are a fixed set: select, from, join, where, groupBy, having, order, union, unionOrder. Passing any other $type fails array_key_exists() and throws InvalidArgumentException, because an unknown slot would silently lose its bindings.

Solutions

  1. Use one of the documented types: 'select', 'from', 'join', 'where', 'groupBy', 'having', 'order', 'union', 'unionOrder'.
  2. Rely on addBinding() / the fluent where() calls instead of setBindings() unless you really need to overwrite a slot.
  3. Double-check the type against array_keys($query->getRawBindings()) in debugging.

Example fix

// before
->setBindings([1, 2], 'wheres')

// after
->setBindings([1, 2], 'where')
Defensive patterns

Strategy: validation

Validate before calling

const VALID_BINDINGS = ['select','from','join','where','groupBy','having','order','union','unionOrder'];
if (! in_array($type, VALID_BINDINGS, true)) {
    throw new InvalidArgumentException('Invalid binding type: ' . $type);
}
$query->setBindings($bindings, $type);

Type guard

/** @param 'select'|'from'|'join'|'where'|'groupBy'|'having'|'order'|'union'|'unionOrder' $type */
function isValidBindingType(string $type): bool
{
    return in_array($type, ['select','from','join','where','groupBy','having','order','union','unionOrder'], true);
}

Prevention

When it happens

Trigger: ->setBindings([1, 2], 'wheres'), ->setBindings([1], 'limit'), or any typo in the type string.

Common situations: Typos like 'wheres' instead of 'where'; passing 'limit' or 'offset' which are not binding slots; copy-paste from getBindings() output with the wrong key.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/0eb6cdc7ae8fe9bc. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Database/Query/Builder.php:4662

     */
    public function getRawBindings()
    {
        return $this->bindings;
    }

    /**
     * Set the bindings on the query builder.
     *
     * @param  list<mixed>  $bindings
     * @param  "select"|"from"|"join"|"where"|"groupBy"|"having"|"order"|"union"|"unionOrder"  $type
     * @return $this
     *
     * @throws \InvalidArgumentException
     */
    public function setBindings(array $bindings, $type = 'where')
    {
        if (! array_key_exists($type, $this->bindings)) {
            throw new InvalidArgumentException("Invalid binding type: {$type}.");
        }

        $this->bindings[$type] = $bindings;

        return $this;
    }

    /**
     * Add a binding to the query.
     *
     * @param  mixed  $value
     * @param  "select"|"from"|"join"|"where"|"groupBy"|"having"|"order"|"union"|"unionOrder"  $type
     * @return $this
     *
     * @throws \InvalidArgumentException
     */
    public function addBinding($value, $type = 'where')
    {

View on GitHub (pinned to e0f6eb3518)