30 lines
632 B
PHP
30 lines
632 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models;
|
||
|
|
||
|
use Spatie\MediaLibrary\MediaCollections\Models\Media as SpatieMedia;
|
||
|
|
||
|
class Media extends SpatieMedia
|
||
|
{
|
||
|
protected $guarded = ['id'];
|
||
|
|
||
|
protected $table = 'app_media';
|
||
|
|
||
|
public function replaceUseKey($key): self
|
||
|
{
|
||
|
self::delete();
|
||
|
return $this->model
|
||
|
->addMediaFromDisk($key, 'public')
|
||
|
->usingFileName($key)
|
||
|
->toMediaCollection($this->collection_name);
|
||
|
}
|
||
|
|
||
|
protected function casts()
|
||
|
{
|
||
|
return [
|
||
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
||
|
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||
|
];
|
||
|
}
|
||
|
}
|