Modifs Relation

This commit is contained in:
Cassandre Cantet 2017-10-12 00:02:50 +02:00
parent 9f448ef69c
commit 7416cf37ec
1 changed files with 9 additions and 11 deletions

View File

@ -213,22 +213,20 @@ class Image extends Model
*/ */
public static function createRelation(Model $class, $relationName) public static function createRelation(Model $class, $relationName)
{ {
$instance = $class->newRelatedInstance(static::class);
$instance = $class->newRelatedInstance(self::class); $foreignPivotKey = 'relation_id';
$relatedPivotKey = 'image_id';
$foreignKey = 'relation_id';
$relatedKey = 'image_id';
$name = 'relation';
$table = 'associate_images'; $table = 'associate_images';
$inverse = false; $name = 'relation';
$relation = new MorphToMany( $morph = new MorphToMany(
$instance->newQuery(), $class, $name, $table, $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() public function toArray()