diff --git a/src/Model/Image.php b/src/Model/Image.php index d110c6c..726b422 100755 --- a/src/Model/Image.php +++ b/src/Model/Image.php @@ -213,22 +213,20 @@ class Image extends Model */ public static function createRelation(Model $class, $relationName) { - - $instance = $class->newRelatedInstance(self::class); - - $foreignKey = 'relation_id'; - $relatedKey = 'image_id'; - $name = 'relation'; + $instance = $class->newRelatedInstance(static::class); + $foreignPivotKey = 'relation_id'; + $relatedPivotKey = 'image_id'; $table = 'associate_images'; - $inverse = false; + $name = 'relation'; - $relation = new MorphToMany( + $morph = new MorphToMany( $instance->newQuery(), $class, $name, $table, - $foreignKey, $relatedKey, $relationName, $inverse + $foreignPivotKey, $relatedPivotKey, $class->getKeyName(), + $instance->getKeyName(), $relationName, false ); - $relation->withPivot('position'); + $morph->withPivot('position'); - return $relation; + return $morph; } public function toArray()