protected function associateMorphTo(array &$formatters, MorphTo $relation, $seeding) {
        // Removes the table names from the foreign key and the morph type.
        $foreignKey = last(explode('.', $relation->{$this->getBelongsToForeignKeyNameMethod()}()));
        $morphType = last(explode('.', $relation->getMorphType()));

        $alwaysAssociate = $this->columns[$foreignKey]->getNotnull() || !$seeding;

        $formatters[$foreignKey] = function ($model, $insertedPKs) use ($alwaysAssociate) {
            if (!($morphOwner = $this->pickMorphOwner($insertedPKs, $alwaysAssociate))) {
                return null;
            }

            $randomElement = $this->generator->randomElement($insertedPKs[$morphOwner]);

            return $randomElement;
        };

        $formatters[$morphType] = function ($model, $insertedPKs) use ($alwaysAssociate) {
            if (!($morphOwner = $this->pickMorphOwner($insertedPKs, $alwaysAssociate))) {
                return null;
            }

            return (new $morphOwner)->getMorphClass();
        };
    }
protected function associateMorphTo(array &$formatters, MorphTo $relation, $seeding) {
        // Removes the table names from the foreign key and the morph type.
        $foreignKey = last(explode('.', $relation->{$this->getBelongsToForeignKeyNameMethod()}()));
        $morphType = last(explode('.', $relation->getMorphType()));

        $alwaysAssociate = $this->columns[$foreignKey]->getNotnull() || !$seeding;

        $formatters[$foreignKey] = function ($model, $insertedPKs) use ($alwaysAssociate) {
            if (!($morphOwner = $this->pickMorphOwner($insertedPKs, $alwaysAssociate))) {
                return null;
            }

            $randomElement = $this->generator->randomElement($insertedPKs[$morphOwner]);

            return $randomElement;
        };

        $formatters[$morphType] = function ($model, $insertedPKs) use ($alwaysAssociate) {
            if (!($morphOwner = $this->pickMorphOwner($insertedPKs, $alwaysAssociate))) {
                return null;
            }

            return (new $morphOwner)->getMorphClass();
        };
    }
protected function associateMorphTo ( array & $ formatters , MorphTo $ relation , $ seeding ) { // Removes the table names from the foreign key and the morph type. $ foreignKey = last ( explode ( '.' , $ relation -> { $ this -> getBelongsToForeignKeyNameMethod ( ) } ( ) ) ) ; $ morphType = last ( explode ( '.' , $ relation -> getMorphType ( ) ) ) ; $ alwaysAssociate = $ this -> columns [ $ foreignKey ] -> getNotnull ( ) || ! $ seeding ; $ formatters [ $ foreignKey ] = function ( $ model , $ insertedPKs ) use ( $ alwaysAssociate ) { if ( ! ( $ morphOwner = $ this -> pickMorphOwner ( $ insertedPKs , $ alwaysAssociate ) ) ) { return null ; } $ randomElement = $ this -> generator -> randomElement ( $ insertedPKs [ $ morphOwner ] ) ; return $ randomElement ; } ; $ formatters [ $ morphType ] = function ( $ model , $ insertedPKs ) use ( $ alwaysAssociate ) { if ( ! ( $ morphOwner = $ this -> pickMorphOwner ( $ insertedPKs , $ alwaysAssociate ) ) ) { return null ; } return ( new $ morphOwner ) -> getMorphClass ( ) ; } ; }
Set the closure that will be used to populate the foreign key of a Morph To relation.

@param  array    $formatters
@param  MorphTo  $relation
@param  bool     $seeding
@return void
Set the closure that will be used to populate the foreign key of a Morph To relation .