foreignKey = $foreignKey; $this->localKey = $localKey; parent::__construct($name, $builder); } /** * Get loaded items * * @return array */ protected function getLoadedItems(): array { return $this->builder->whereIn($this->foreignKey, $this->extractKeyValues())->get(); } /** * Extract foreign key values * * @return array */ protected function extractKeyValues(): array { return array_column($this->items, $this->localKey); } }