You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

48 lines
977 B

<?php
namespace App\Entities\Projects;
use Storage;
use Illuminate\Database\Eloquent\Model;
class File extends Model
{
protected $fillable = ['fileable_id', 'fileable_type', 'type_id', 'filename', 'title', 'description'];
public function fileable()
{
return $this->morphTo();
}
public function project()
{
return $this->morphTo('fileable', Project::class);
}
public function getSize()
{
return $this->fileExists() ? \Storage::size('public/files/'.$this->filename) : 0;
}
public function getDate()
{
return $this->updated_at->format('Y-m-d');
}
public function getTime()
{
return $this->updated_at->format('H:i:s');
}
public function fileExists()
{
return \Storage::exists('public/files/'.$this->filename);
}
public function delete()
{
Storage::delete('public/files/'.$this->filename);
return parent::delete();
}
}