web-api/app/Models/Media.php
梁朝伟 7f3db2ed48 init
2024-11-13 19:23:49 +08:00

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',
];
}
}