Skip to content

Commit 4624b89

Browse files
dbpolitotaylorotwell
authored andcommitted
Adding support to collection on Eloquent::find (#19019)
1 parent e191810 commit 4624b89

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Illuminate/Database/Eloquent/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public function fromQuery($query, $bindings = [])
266266
*/
267267
public function find($id, $columns = ['*'])
268268
{
269-
if (is_array($id)) {
269+
if (is_array($id) || $id instanceof Arrayable) {
270270
return $this->findMany($id, $columns);
271271
}
272272

tests/Database/DatabaseEloquentBuilderTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ public function testFindWithMany()
104104
$this->assertEquals('baz', $result);
105105
}
106106

107+
public function testFindWithManyUsingCollection()
108+
{
109+
$ids = collect([1, 2]);
110+
$builder = m::mock('Illuminate\Database\Eloquent\Builder[get]', [$this->getMockQueryBuilder()]);
111+
$builder->getQuery()->shouldReceive('whereIn')->once()->with('foo_table.foo', $ids);
112+
$builder->setModel($this->getMockModel());
113+
$builder->shouldReceive('get')->with(['column'])->andReturn('baz');
114+
115+
$result = $builder->find($ids, ['column']);
116+
$this->assertEquals('baz', $result);
117+
}
118+
107119
public function testFirstMethod()
108120
{
109121
$builder = m::mock('Illuminate\Database\Eloquent\Builder[get,take]', [$this->getMockQueryBuilder()]);

0 commit comments

Comments
 (0)