public function loadModels(Models $models, $flags = null) { $models = $models->filter(function ($model) { return $model->{$this->classKey}; }); $groups = Arr::groupBy($models->toArray(), function ($model) { return $model->{$this->classKey}; }); foreach ($groups as $modelClass => &$models) { $keys = Arr::pluckUniqueProperty($models, $this->key); if ($keys) { $models = $modelClass::whereIn($this->getForeignKey(), $keys)->setFlags($flags)->loadRaw(); } else { $models = []; } } return Arr::flatten($groups); }
/** * @covers ::flatten * @dataProvider dataFlatten */ public function testFlatten($array, $expected) { $this->assertSame($expected, Arr::flatten($array)); }