diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 8eb6c6ddc1db..0b2a7bb5c3b4 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1773,7 +1773,7 @@ public function with($relations, $callback = null) if ($callback instanceof Closure) { $eagerLoad = $this->parseWithRelations([$relations => $callback]); } else { - $eagerLoad = $this->parseWithRelations(is_string($relations) ? func_get_args() : $relations); + $eagerLoad = $this->parseWithRelations(is_string($relations) ? array_filter(func_get_args()) : $relations); } $this->eagerLoad = array_merge($this->eagerLoad, $eagerLoad); diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index 6b506b2dad46..783bea2fd5c3 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -866,6 +866,13 @@ public function testEagerLoadParsingSetsProperRelationships() $this->assertInstanceOf(Closure::class, $eagers['orders']); $this->assertInstanceOf(Closure::class, $eagers['orders.lines']); + $builder = $this->getBuilder(); + $builder->with('orders', null); + $eagers = $builder->getEagerLoads(); + + $this->assertEquals(['orders'], array_keys($eagers)); + $this->assertInstanceOf(Closure::class, $eagers['orders']); + $builder = $this->getBuilder(); $builder->with(['orders.lines']); $eagers = $builder->getEagerLoads();