first
This commit is contained in:
44
app/Http/Controllers/DocumentDownloadController.php
Normal file
44
app/Http/Controllers/DocumentDownloadController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ApplicationDocument;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class DocumentDownloadController extends Controller
|
||||
{
|
||||
public function admin(ApplicationDocument $document): StreamedResponse
|
||||
{
|
||||
abort_unless(
|
||||
in_array($document->document_type, ApplicationDocument::ALLOWED_FOR_ADMIN, true),
|
||||
403
|
||||
);
|
||||
abort_unless(Storage::disk($document->disk)->exists($document->path), 404);
|
||||
|
||||
activity('documents')
|
||||
->performedOn($document)
|
||||
->causedBy(request()->user())
|
||||
->withProperties(['document_type' => $document->document_type])
|
||||
->log('document_downloaded_by_admin');
|
||||
|
||||
return Storage::disk($document->disk)->download($document->path, $document->original_name);
|
||||
}
|
||||
|
||||
public function finance(ApplicationDocument $document): StreamedResponse
|
||||
{
|
||||
abort_unless(
|
||||
in_array($document->document_type, ApplicationDocument::ALLOWED_FOR_FINANCE, true),
|
||||
403
|
||||
);
|
||||
abort_unless(Storage::disk($document->disk)->exists($document->path), 404);
|
||||
|
||||
activity('documents')
|
||||
->performedOn($document)
|
||||
->causedBy(request()->user())
|
||||
->withProperties(['document_type' => $document->document_type])
|
||||
->log('bank_statement_downloaded_by_finance');
|
||||
|
||||
return Storage::disk($document->disk)->download($document->path, $document->original_name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user