update model to use parent_id

This commit is contained in:
2023-12-01 07:42:36 +10:00
parent 169232766f
commit 0b3f65be11

View File

@@ -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');
}
}