Repository: laravel/framework
File: src/Illuminate/Database/Query/Builder.php (PHP)

Code before:
        if ($values instanceof \DatePeriod) {
            $values = $this->resolveDatePeriodBounds($values);
        }

        $this->wheres[] = compact('type', 'column', 'values', 'boolean', 'not');

        $this->addBinding(array_slice($this->cleanBindings(Arr::flatten($values)), 0, 2), 'where');

        return $this;
    }

    /**
     * Resolve the start and end dates from a DatePeriod.
     *
     * @param  \DatePeriod  $period
     * @return array
     */
    protected function resolveDatePeriodBounds(\DatePeriod $period)
    {
        $start = $period->getStartDate();
        $end = $period->getEndDate();

        if ($end === null) {
            $end = clone $start;

            for ($i = 0; $i < $period->getRecurrences(); $i++) {
                $end = $end->add($period->getDateInterval());
            }
        }

        return [$start, $end];
    }

    /**
     * Add a "where between" statement using columns to the query.
     *
     * @param  \Illuminate\Contracts\Database\Query\Expression|string  $column
     * @param  string  $boolean
     * @param  bool  $not
     * @return $this
     */
    public function whereBetweenColumns($column, array $values, $boolean = 'and', $not = false)
    {
        $type = 'betweenColumns';

        if ($this->isQueryable($column)) {
            [$sub, $bindings] = $this->createSub($column);

            return $this->addBinding($bindings, 'where')
                ->whereBetweenColumns(new Expression('('.$sub.')'), $values, $boolean, $not);
        }

Review comment (performance):
It might slightly improve performance if you avoid getting the recurrences on every iteration

```suggestion
            $recurrences = $period->getRecurrences();
            for ($i = 0; $i < $recurrences; $i++) {
```
or

```suggestion
            for ($i = 0, $recurrences = $period->getRecurrences(); $i < $recurrences(); $i++) {
```

Code after:

        if ($values instanceof DatePeriod) {
            $values = $this->resolveDatePeriodBounds($values);
        }

        $this->wheres[] = compact('type', 'column', 'values', 'boolean', 'not');

        $this->addBinding(array_slice($this->cleanBindings(Arr::flatten($values)), 0, 2), 'where');

        return $this;
    }

    /**
     * Add a "where between" statement using columns to the query.
     *
     * @param  \Illuminate\Contracts\Database\Query\Expression|string  $column
     * @param  string  $boolean
     * @param  bool  $not
     * @return $this
     */
    public function whereBetweenColumns($column, array $values, $boolean = 'and', $not = false)
    {
        $type = 'betweenColumns';

        if ($this->isQueryable($column)) {
            [$sub, $bindings] = $this->createSub($column);

            return $this->addBinding($bindings, 'where')
                ->whereBetweenColumns(new Expression('('.$sub.')'), $values, $boolean, $not);
        }

        $this->wheres[] = compact('type', 'column', 'values', 'boolean', 'not');

        return $this;
    }

    /**
     * Add an "or where between" statement to the query.
     *
     * @param  \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*>|\Illuminate\Contracts\Database\Query\Expression|string  $column
     * @return $this
     */
    public function orWhereBetween($column, iterable $values)
    {
        return $this->whereBetween($column, $values, 'or');
    }

    /**
     * Add an "or where between" statement using columns to the query.
     *
     * @param  \Illuminate\Contracts\Database\Query\Expression|string  $column