Skip to content

[13.x] Support LazyCollection values in between clauses - #61678

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
vikas-kushwaha-dev:fix-lazy-collection-between
Sep 22, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
vikas-kushwaha-dev:fix-lazy-collection-between

Conversation

@vikas-kushwaha-dev

@vikas-kushwaha-dev vikas-kushwaha-dev commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

I have encountered a issue where when i pass LazyCollection::make([100, 200]) in whereBetween() and havingBetween() of SQL it thows error Error: Cannot use object of type Illuminate\Support\LazyCollection as array.
But both functions whereBetween() and havingBetween() accepts iterable but it is not converting the LazyCollection
into an indexed array.

Proposed Fix:
elseif ($values instanceof Traversable) { $values = iterator_to_array($values, false); }
adding Traversable to convert it into indexed array.

Added Test:
$builder = $this->getBuilder(); $builder->select('*')->from('users')->whereBetween('id', LazyCollection::make([1, 2])); $this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql()); $this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());

1 2

@vikas-kushwaha-dev
vikas-kushwaha-dev marked this pull request as draft September 22, 2026 20:24
@vikas-kushwaha-dev
vikas-kushwaha-dev marked this pull request as ready for review September 22, 2026 20:24
@taylorotwell
taylorotwell merged commit 5b40180 into laravel:13.x Sep 22, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants