raffles document uploader added / Free Resource Completed

This commit is contained in:
2025-08-03 00:01:49 +05:45
parent efa9231391
commit a3b863970e
25 changed files with 472 additions and 1062 deletions

View File

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