From 64ab9a1d566a4e43c07e5dbea24726d50e364884 Mon Sep 17 00:00:00 2001 From: James Collins Date: Thu, 30 Nov 2023 21:51:41 +1000 Subject: [PATCH] update model --- app/Models/Media.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/Models/Media.php b/app/Models/Media.php index 5a5464c..2c96bd2 100644 --- a/app/Models/Media.php +++ b/app/Models/Media.php @@ -4,8 +4,34 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Media extends Model { use HasFactory; + + protected $fillable = ['parent_id', 'filename', 'path', 'type', 'metadata', 'size']; + + protected $casts = [ + 'metadata' => 'array', + ]; + + /** + * Get the original media of this variation. + */ + public function parent(): BelongsTo + { + return $this->belongsTo(Media::class, 'parent_id'); + } + + /** + * Get the variations for the media. + */ + + + public function variations(): HasMany + { + return $this->hasMany(Media::class, 'original_media_id'); + } }