raffles document uploader added / Free Resource Completed
This commit is contained in:
@@ -13,9 +13,16 @@ class Document extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['title', 'file_path'];
|
||||
protected $fillable = ['title', 'file_path', 'collection_name', 'order'];
|
||||
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
$model->order = ($model::max('order') ?? 0) + 1;
|
||||
});
|
||||
}
|
||||
|
||||
public function documentable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
@@ -23,13 +30,13 @@ class Document extends Model
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
$path = $this->document_path;
|
||||
$path = $this->collection_name . '/' . $this->file_path;
|
||||
return Storage::disk('public')->url($path);
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
$path = $this->document_path;
|
||||
$path = $this->collection_name . '/' . $this->file_path;
|
||||
|
||||
if (Storage::disk('public')->exists($path)) {
|
||||
$sizeInBytes = Storage::disk('public')->size($path);
|
||||
@@ -41,13 +48,13 @@ class Document extends Model
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return pathinfo($this->document_path, PATHINFO_EXTENSION);
|
||||
return pathinfo($this->file_path, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
public function isImageFile()
|
||||
{
|
||||
$imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'tiff', 'tif', 'ico'];
|
||||
$extension = pathinfo($this->document_path, PATHINFO_EXTENSION);
|
||||
$extension = pathinfo($this->file_path, PATHINFO_EXTENSION);
|
||||
return in_array(Str::lower($extension), $imageExtensions);
|
||||
}
|
||||
|
||||
@@ -56,7 +63,7 @@ class Document extends Model
|
||||
return Attribute::make(
|
||||
get: function (mixed $value, array $attributes) {
|
||||
$collectionName = $attributes['collection_name'];
|
||||
$path = $attributes['document_path'];
|
||||
$path = $attributes['file_path'];
|
||||
return "{$collectionName}/{$path}";
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user