diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index ab632694fe..407c346bb8 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -137,7 +137,10 @@ class InvoiceController extends Controller //if only 1 pdf, output to buffer for download if ($invoices->count() == 1) { - return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($invoices->first()->pdf_file_path())); + return response()->streamDownload(function () use($invoices) { + echo file_get_contents($invoices->first()->pdf_file_path()); + }, basename($invoices->first()->pdf_file_path())); + //return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($invoices->first()->pdf_file_path())); } # enable output of HTTP headers diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index 8421ea3310..56b7e39638 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -74,7 +74,10 @@ class QuoteController extends Controller } if ($quotes->count() == 1) { - return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($quotes->first()->pdf_file_path())); + return response()->streamDownload(function () use($invoices) { + echo file_get_contents($invoices->first()->pdf_file_path()); + }, basename($invoices->first()->pdf_file_path())); + //return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($quotes->first()->pdf_file_path())); } # enable output of HTTP headers diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 8b56a5685c..6e2d4e2145 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -527,7 +527,10 @@ class CreditController extends BaseController } break; case 'download': - return response()->download(TempFile::path($credit->pdf_file_path()), basename($credit->pdf_file_path())); + return response()->streamDownload(function () use($credit) { + echo file_get_contents($credit->pdf_file_path()); + }, basename($credit->pdf_file_path())); + //return response()->download(TempFile::path($credit->pdf_file_path()), basename($credit->pdf_file_path())); break; case 'archive': $this->credit_repository->archive($credit); diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php index 3d71de8503..9c20cd2acd 100644 --- a/app/Http/Controllers/DocumentController.php +++ b/app/Http/Controllers/DocumentController.php @@ -2,9 +2,14 @@ namespace App\Http\Controllers; +use App\Http\Requests\Document\EditDocumentRequest; +use App\Http\Requests\Document\ShowDocumentRequest; +use App\Http\Requests\Document\StoreDocumentRequest; +use App\Http\Requests\Document\UpdateDocumentRequest; +use App\Models\Document; use Illuminate\Http\Request; -class DocumentController extends Controller +class DocumentController extends BaseController { /** * Display a listing of the resource. @@ -32,7 +37,7 @@ class DocumentController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ - public function store(Request $request) + public function store(StoreDocumentRequest $request) { // } @@ -43,9 +48,13 @@ class DocumentController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function show($id) + public function show(ShowDocumentRequest $request, Document $document) { - // + return response()->streamDownload(function () use($document) { + echo file_get_contents($document->generateUrl()); + }, basename($document->generateUrl())); + + //return response()->download($document->generateUrl()); } /** @@ -54,7 +63,7 @@ class DocumentController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function edit($id) + public function edit(EditDocumentRegquest $request, Document $document) { // } @@ -66,7 +75,7 @@ class DocumentController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function update(Request $request, $id) + public function update(UpdateDocumentRequest $request, Document $document) { // } @@ -77,7 +86,7 @@ class DocumentController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function destroy($id) + public function destroy(DestroyDocumentRequest $request, Document $document) { // } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 48251ead31..fa22c7ac82 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -660,7 +660,10 @@ class InvoiceController extends BaseController } break; case 'download': - return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path())); + return response()->streamDownload(function () use($invoice) { + echo file_get_contents($invoice->pdf_file_path()); + }, basename($invoice->pdf_file_path())); + //return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path())); break; case 'restore': $this->invoice_repo->restore($invoice); diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 855c58c201..ee18a597d0 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -661,7 +661,10 @@ class QuoteController extends BaseController # code... break; case 'download': - return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path())); + return response()->streamDownload(function () use($quote) { + echo file_get_contents($quote->pdf_file_path()); + }, basename($quote->pdf_file_path())); + //return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path())); break; case 'archive': $this->invoice_repo->archive($quote); diff --git a/app/Models/Company.php b/app/Models/Company.php index 8185da8693..89f3afaacb 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -134,6 +134,11 @@ class Company extends BaseModel self::ENTITY_RECURRING_QUOTE => 2048, ]; + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } + public function getEntityType() { return Company::class; diff --git a/app/Models/Document.php b/app/Models/Document.php index f46e8276e1..b977c547e8 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -112,4 +112,11 @@ class Document extends BaseModel return null; } + + public function generateRoute($absolute = false) + { + return route('api.documents.show', ['document' => $this->hashed_id]); + + //return route('document.show', ['document' => $this->hashed_id]); + } } diff --git a/app/Transformers/DocumentTransformer.php b/app/Transformers/DocumentTransformer.php index 6f34407b08..a1f9c8ca51 100644 --- a/app/Transformers/DocumentTransformer.php +++ b/app/Transformers/DocumentTransformer.php @@ -37,7 +37,7 @@ class DocumentTransformer extends EntityTransformer 'assigned_user_id' => $this->encodePrimaryKey($document->assigned_user_id), 'project_id' => $this->encodePrimaryKey($document->project_id), 'vendor_id' => $this->encodePrimaryKey($document->vendor_id), - 'url' => (string) $document->generateUrl() ?: '', + 'url' => (string) $document->generateRoute() ?: '', 'preview' => (string) $document->preview ?: '', 'name' => (string) $document->name, 'type' => (string) $document->type,