src/HasRelationships.php
protected function hasOneOrManyDeepForeignKeys(Model $related, array $throughParents, array $foreignKeys)
    {
        foreach (array_merge([$this], $throughParents) as $i => $instance) {
            /** @var \Illuminate\Database\Eloquent\Model $instance */
            if (! isset($foreignKeys[$i])) {
                if ($instance instanceof Pivot) {
                    $foreignKeys[$i] = ($throughParents[$i] ?? $related)->getKeyName();
                } else {
                    $foreignKeys[$i] = $instance->getForeignKey();
                }
            }
        }

        return $foreignKeys;
    }
protected function hasOneOrManyDeepForeignKeys(Model $related, array $throughParents, array $foreignKeys)
    {
        foreach (array_merge([$this], $throughParents) as $i => $instance) {
            /** @var \Illuminate\Database\Eloquent\Model $instance */
            if (! isset($foreignKeys[$i])) {
                if ($instance instanceof Pivot) {
                    $foreignKeys[$i] = ($throughParents[$i] ?? $related)->getKeyName();
                } else {
                    $foreignKeys[$i] = $instance->getForeignKey();
                }
            }
        }

        return $foreignKeys;
    }
protected function hasOneOrManyDeepForeignKeys ( Model $ related , array $ throughParents , array $ foreignKeys ) { foreach ( array_merge ( [ $ this ] , $ throughParents ) as $ i => $ instance ) { /** @var \Illuminate\Database\Eloquent\Model $instance */ if ( ! isset ( $ foreignKeys [ $ i ] ) ) { if ( $ instance instanceof Pivot ) { $ foreignKeys [ $ i ] = ( $ throughParents [ $ i ] ?? $ related ) -> getKeyName ( ) ; } else { $ foreignKeys [ $ i ] = $ instance -> getForeignKey ( ) ; } } } return $ foreignKeys ; }
Prepare the foreign keys for a has-one-deep or has-many-deep relationship.

@param  \Illuminate\Database\Eloquent\Model $related
@param  \Illuminate\Database\Eloquent\Model[]  $throughParents
@param  array  $foreignKeys
@return array
Prepare the foreign keys for a has - one - deep or has - many - deep relationship .