public function linkModels(Models $models, Models $foreign, Closure $yield)
    {
        foreach ($models as $model) {

            $linked = [];

            foreach ($foreign as $foreignModel) {
                if ($this->areLinked($model, $foreignModel)) {
                    $linked []= $foreignModel;
                }
            }

            $link = $this->newLinkFrom($model, $linked);

            $yield($link);
        }
    }
public function linkModels(Models $models, Models $foreign, Closure $yield)
    {
        foreach ($models as $model) {

            $linked = [];

            foreach ($foreign as $foreignModel) {
                if ($this->areLinked($model, $foreignModel)) {
                    $linked []= $foreignModel;
                }
            }

            $link = $this->newLinkFrom($model, $linked);

            $yield($link);
        }
    }
public function linkModels ( Models $ models , Models $ foreign , Closure $ yield ) { foreach ( $ models as $ model ) { $ linked = [ ] ; foreach ( $ foreign as $ foreignModel ) { if ( $ this -> areLinked ( $ model , $ foreignModel ) ) { $ linked [ ] = $ foreignModel ; } } $ link = $ this -> newLinkFrom ( $ model , $ linked ) ; $ yield ( $ link ) ; } }
Iterate models and foreign models one by one and and assign links based on the areLinked method
Yeild the resulted links one by one for further processing.

@param Models  $models
@param Models  $foreign
@param Closure $yield   call for each link
Iterate models and foreign models one by one and and assign links based on the areLinked method Yeild the resulted links one by one for further processing .