feat: Implement Document Module with Dropzone file upload functionality
- Added DocumentController for handling document uploads and management. - Created Document model with necessary attributes and relationships. - Implemented DocumentService for business logic related to documents. - Set up routes for document management in both web and API contexts. - Developed views for document upload using Dropzone for file handling. - Included necessary assets and styles for the Document module. - Created migration for documents table with appropriate fields. - Added configuration and service provider for the Document module.
This commit is contained in:
69
Modules/Document/app/Models/Document.php
Normal file
69
Modules/Document/app/Models/Document.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Document\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Document extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['title', 'file_path'];
|
||||
|
||||
|
||||
public function documentable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
$path = $this->document_path;
|
||||
return Storage::disk('public')->url($path);
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
$path = $this->document_path;
|
||||
|
||||
if (Storage::disk('public')->exists($path)) {
|
||||
$sizeInBytes = Storage::disk('public')->size($path);
|
||||
return round($sizeInBytes / 1024, 2) . " KB";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return pathinfo($this->document_path, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
public function isImageFile()
|
||||
{
|
||||
$imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'tiff', 'tif', 'ico'];
|
||||
$extension = pathinfo($this->document_path, PATHINFO_EXTENSION);
|
||||
return in_array(Str::lower($extension), $imageExtensions);
|
||||
}
|
||||
|
||||
protected function documentPath(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function (mixed $value, array $attributes) {
|
||||
$collectionName = $attributes['collection_name'];
|
||||
$path = $attributes['document_path'];
|
||||
return "{$collectionName}/{$path}";
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function scopeActive($query, int $status = 1)
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
}
|
0
Modules/Document/app/Models/Scopes/.gitkeep
Normal file
0
Modules/Document/app/Models/Scopes/.gitkeep
Normal file
Reference in New Issue
Block a user