laravel/framework · error · InvalidArgumentException

Invalid binding type: {$type}.

Error message

Invalid binding type: {$type}.

What it means

Thrown by setBindings when $type is not one of the nine valid binding buckets: 'select', 'from', 'join', 'where', 'groupBy', 'having', 'order', 'union', 'unionOrder'. setBindings replaces the entire binding list for that bucket; an unknown type would leave orphan bindings that never get rendered, so the request is rejected up front.

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

Solutions

  1. Use one of the nine valid types: select, from, join, where, groupBy, having, order, union, unionOrder.
  2. Whitelist before calling: `$valid = ['select','from','join','where','groupBy','having','order','union','unionOrder']; in_array($type, $valid) or throw ...`.
  3. Avoid setBindings unless you are reconstructing a query from cached SQL; prefer addBinding/where etc. which manage buckets for you.
  4. Check the message: it echoes the bad type so the typo is visible.

Example fix

// before
$query->setBindings([1, 2], 'orderBy');
// => Invalid binding type: orderBy.

// after
$query->setBindings([1, 2], 'order');
Defensive patterns

Strategy: type-guard

Validate before calling

$valid = ['select','from','join','where','groupBy','having','order','union','unionOrder'];
if (! in_array($type, $valid, true)) {
    throw new \InvalidArgumentException('setBindings type must be one of: '.implode(',', $valid));
}

Type guard

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

Try / catch

// Validate the type before calling; setBindings is a low-level API, prefer fluent builders.

Prevention

When it happens

Trigger: `->setBindings([1,2], 'orderBy')` (typo for 'order'). Passing `'limit'` or `'offset'` which are not binding buckets. Passing a computed string that resolves to a non-bucket name.

Common situations: Refactoring from positional to typed bindings with a wrong bucket name; code that builds the type from a column-friendly name; copy-paste between setBindings and addBinding with inconsistent enum sets.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/0eb6cdc7ae8fe9bc.json. Report an issue: GitHub.