relationships[$relationship] = null; } } /** * Match eagerly loaded child models to their parent models. * * @param array $parents * @param array $children * @return void */ public function match($relationship, &$parents, $children) { $foreign = $this->foreign_key(); foreach ($parents as &$parent) { $matching = array_first($children, function($k, $v) use (&$parent, $foreign) { return $v->$foreign == $parent->get_key(); }); $parent->relationships[$relationship] = $matching; } } }