Files
prn2026/app/Http/Controllers/DocumentDownloadController.php
2026-06-03 08:51:22 +08:00

45 lines
1.5 KiB
PHP

<?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);
}
}