From 0b3f65be11ffe317d6ee8e3969ee569de2eb03c4 Mon Sep 17 00:00:00 2001 From: James Collins Date: Fri, 1 Dec 2023 07:42:36 +1000 Subject: [PATCH] update model to use parent_id --- app/Models/Media.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/Models/Media.php b/app/Models/Media.php index 2c96bd2..c130c18 100644 --- a/app/Models/Media.php +++ b/app/Models/Media.php @@ -11,14 +11,34 @@ class Media extends Model { use HasFactory; - protected $fillable = ['parent_id', 'filename', 'path', 'type', 'metadata', 'size']; + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'parent_id', + 'filename', + 'path', + 'type', + 'metadata', + 'size' + ]; + /** + * The attributes that should be cast. + * + * @var array + */ protected $casts = [ 'metadata' => 'array', ]; + /** * Get the original media of this variation. + * + * @return BelongsTo */ public function parent(): BelongsTo { @@ -27,11 +47,11 @@ class Media extends Model /** * Get the variations for the media. + * + * @return HasMany */ - - public function variations(): HasMany { - return $this->hasMany(Media::class, 'original_media_id'); + return $this->hasMany(Media::class, 'parent_id'); } }