DONE: layout letter with letterhead and footer, notification for newly...

This commit is contained in:
ISMAIL MASSERAN
2026-06-28 02:16:49 +00:00
parent 94ecbe5887
commit 034ecf947f
400 changed files with 29802 additions and 5446 deletions
+14 -20
View File
@@ -19,22 +19,16 @@ class DocumentService
string $documentType = 'general',
?string $description = null
): Document {
// Generate unique filename
$fileName = time().'_'.$file->getClientOriginalName();
// Store file in a folder named after the model
$folderName = strtolower(class_basename($model));
$filePath = $file->storeAs("documents/{$folderName}", $fileName, 'public');
$filePath = $file->storeAs("documents/{$folderName}", $fileName, Document::STORAGE_DISK);
// Create document record
return Document::create([
'documentable_type' => get_class($model),
'documentable_id' => $model->id,
'document_name' => $file->getClientOriginalName(),
'document_path' => $filePath,
return $model->documents()->create([
'name' => $file->getClientOriginalName(),
'path' => $filePath,
'file_size' => $file->getSize(),
'mime_type' => $file->getClientMimeType(),
'document_type' => $documentType,
'type' => $documentType,
'description' => $description,
'uploaded_by' => auth()->id(),
]);
@@ -43,7 +37,7 @@ class DocumentService
/**
* Delete a document.
*/
public function deleteDocument(int $documentId): bool
public function deleteDocument(string $documentId): bool
{
$document = Document::findOrFail($documentId);
@@ -58,7 +52,7 @@ class DocumentService
$query = $model->documents();
if ($documentType) {
$query->where('document_type', $documentType);
$query->where('type', $documentType);
}
return $query->with('uploadedBy')->get();
@@ -67,7 +61,7 @@ class DocumentService
/**
* Get document by ID with validation.
*/
public function getDocument(int $documentId): Document
public function getDocument(string $documentId): Document
{
return Document::with('uploadedBy')->findOrFail($documentId);
}
@@ -75,15 +69,17 @@ class DocumentService
/**
* Download a document.
*/
public function downloadDocument(int $documentId)
public function downloadDocument(string $documentId)
{
$document = $this->getDocument($documentId);
if (! Storage::exists($document->document_path)) {
$disk = Storage::disk(Document::STORAGE_DISK);
if (! $disk->exists($document->path)) {
throw new Exception('File not found');
}
return Storage::download($document->document_path, $document->document_name);
return $disk->download($document->path, $document->name);
}
/**
@@ -94,7 +90,7 @@ class DocumentService
$query = $model->documents();
if ($documentType) {
$query->where('document_type', $documentType);
$query->where('type', $documentType);
}
return $query->count();
@@ -140,12 +136,10 @@ class DocumentService
$supportedTypes = $this->getSupportedFileTypes();
$maxSize = $this->getMaxFileSize() * 1024; // Convert to bytes
// Check file size
if ($file->getSize() > $maxSize) {
throw new Exception('File size exceeds maximum limit of '.$this->getMaxFileSize().'KB');
}
// Check mime type
if (! in_array($file->getClientMimeType(), $supportedTypes)) {
throw new Exception('File type not supported. Supported types: '.implode(', ', array_keys($supportedTypes)));
}