/** * @return ModelCollection */ public function get() { return $this->collection->findAll(function ($item) { /** @var TableModel $item */ $modelValue = $this->fromKey == $this->model->pk() ? $this->model->id() : $this->model->get($this->fromKey); $relatedValue = $this->foreignKey == $item->pk() ? $item->id() : $item->get($this->foreignKey); return $modelValue == $relatedValue; }); }