Dev/v1.1 (#2)
Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local> Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
@@ -13,12 +13,7 @@ class DocumentService
|
||||
/**
|
||||
* Upload a document for any model.
|
||||
*/
|
||||
public function uploadDocument(
|
||||
Model $model,
|
||||
UploadedFile $file,
|
||||
string $documentType = 'general',
|
||||
?string $description = null
|
||||
): Document {
|
||||
public function uploadDocument(Model $model, UploadedFile $file, string $documentType = 'general', ?string $description = null): Document {
|
||||
$fileName = time().'_'.$file->getClientOriginalName();
|
||||
$folderName = strtolower(class_basename($model));
|
||||
$filePath = $file->storeAs("documents/{$folderName}", $fileName, Document::STORAGE_DISK);
|
||||
@@ -34,6 +29,27 @@ class DocumentService
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store generated file contents (e.g. PDF) for a model.
|
||||
*/
|
||||
public function storeGeneratedDocument(Model $model, string $contents, string $fileName, string $documentType = 'general', string $mimeType = 'application/pdf', ?string $description = null,): Document {
|
||||
$folderName = strtolower(class_basename($model));
|
||||
$storedFileName = time().'_'.$fileName;
|
||||
$filePath = "documents/{$folderName}/{$storedFileName}";
|
||||
|
||||
Storage::disk(Document::STORAGE_DISK)->put($filePath, $contents);
|
||||
|
||||
return $model->documents()->create([
|
||||
'name' => $fileName,
|
||||
'path' => $filePath,
|
||||
'file_size' => strlen($contents),
|
||||
'mime_type' => $mimeType,
|
||||
'type' => $documentType,
|
||||
'description' => $description,
|
||||
'uploaded_by' => auth()->id(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a document.
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,7 @@ class LetterService
|
||||
*/
|
||||
public function pdfResponse(string $view, array $data = [], string $filename = 'letter.pdf'): Response
|
||||
{
|
||||
$pdf = $this->makeBrowsershot($this->renderHtml($view, $data))->pdf();
|
||||
$pdf = $this->renderPdf($view, $data);
|
||||
|
||||
return response($pdf, SymfonyResponse::HTTP_OK, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
@@ -41,6 +41,14 @@ class LetterService
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function renderPdf(string $view, array $data = []): string
|
||||
{
|
||||
return $this->makeBrowsershot($this->renderHtml($view, $data))->pdf();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $overrides
|
||||
* @return array<string, mixed>
|
||||
|
||||
Reference in New Issue
Block a user