protected function pickMorphOwner(array $insertedPKs, $alwaysAssociate)
    {
        $owners = $this->populator->getMorphToClasses(get_class($this->model));

        // We'll share the chosen owner between the foreign key and morph type closures
        // by saving it in $this until the next call to this method.
        if ($this->morphOwner === false) {
            if (!$alwaysAssociate && rand(0, 1)) {
                return $this->morphOwner = null;
            }

            // Filters the owning classes that have been added to Populator.
            $owners = array_filter($owners, function ($owner) use ($insertedPKs) {
                return isset($insertedPKs[$owner]);
            });

            return $this->morphOwner = $this->generator->randomElement($owners);
        }

        return tap($this->morphOwner, function () {
            // We'll unset the picked owner,
            // so it will be picked again randomly when the next model is created.
            $this->morphOwner = false;
        });
    }
protected function pickMorphOwner(array $insertedPKs, $alwaysAssociate)
    {
        $owners = $this->populator->getMorphToClasses(get_class($this->model));

        // We'll share the chosen owner between the foreign key and morph type closures
        // by saving it in $this until the next call to this method.
        if ($this->morphOwner === false) {
            if (!$alwaysAssociate && rand(0, 1)) {
                return $this->morphOwner = null;
            }

            // Filters the owning classes that have been added to Populator.
            $owners = array_filter($owners, function ($owner) use ($insertedPKs) {
                return isset($insertedPKs[$owner]);
            });

            return $this->morphOwner = $this->generator->randomElement($owners);
        }

        return tap($this->morphOwner, function () {
            // We'll unset the picked owner,
            // so it will be picked again randomly when the next model is created.
            $this->morphOwner = false;
        });
    }
protected function pickMorphOwner ( array $ insertedPKs , $ alwaysAssociate ) { $ owners = $ this -> populator -> getMorphToClasses ( get_class ( $ this -> model ) ) ; // We'll share the chosen owner between the foreign key and morph type closures // by saving it in $this until the next call to this method. if ( $ this -> morphOwner === false ) { if ( ! $ alwaysAssociate && rand ( 0 , 1 ) ) { return $ this -> morphOwner = null ; } // Filters the owning classes that have been added to Populator. $ owners = array_filter ( $ owners , function ( $ owner ) use ( $ insertedPKs ) { return isset ( $ insertedPKs [ $ owner ] ) ; } ) ; return $ this -> morphOwner = $ this -> generator -> randomElement ( $ owners ) ; } return tap ( $ this -> morphOwner , function ( ) { // We'll unset the picked owner, // so it will be picked again randomly when the next model is created. $ this -> morphOwner = false ; } ) ; }
Select a random owning class for a Morph To relation.

@param  array[] $insertedPKs
@param  bool    $alwaysAssociate
@return string|null
Select a random owning class for a Morph To relation .