From 7416cf37eca94f14d13793f682637289e34d07a0 Mon Sep 17 00:00:00 2001 From: Cassandre Cantet Date: Thu, 12 Oct 2017 00:02:50 +0200 Subject: [PATCH] Modifs Relation --- src/Model/Image.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) 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()