first commit
This commit is contained in:
47
app/Http/Controllers/DocumentController.php
Normal file
47
app/Http/Controllers/DocumentController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\AppSetting;
|
||||
use App\Models\Submission;
|
||||
use App\Models\SubmissionDocument;
|
||||
use App\Services\DocumentService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
public function __construct(protected DocumentService $documents) {}
|
||||
|
||||
/** Muat naik laporan PDF (perunding sahaja, serahan belum dikunci). */
|
||||
public function store(Request $request, Submission $submission)
|
||||
{
|
||||
$this->authorize('update', $submission);
|
||||
|
||||
$maxKb = (int) AppSetting::get('max_upload_size_kb', config('mbip.max_upload_size_kb', 20480));
|
||||
|
||||
$request->validate([
|
||||
'report' => ['required', 'file', 'mimes:pdf', 'mimetypes:application/pdf', "max:$maxKb"],
|
||||
], [], ['report' => 'laporan PDF']);
|
||||
|
||||
$this->documents->store($submission, $request->file('report'), auth()->user());
|
||||
|
||||
return back()->with('success', 'Laporan PDF berjaya dimuat naik (versi baharu dicipta).');
|
||||
}
|
||||
|
||||
/** Muat turun laporan — dilindungi oleh polisi. */
|
||||
public function download(SubmissionDocument $document)
|
||||
{
|
||||
$this->authorize('view', $document->submission);
|
||||
|
||||
return $this->documents->download($document);
|
||||
}
|
||||
|
||||
public function setActive(SubmissionDocument $document)
|
||||
{
|
||||
$this->authorize('update', $document->submission);
|
||||
|
||||
$this->documents->setActiveVersion($document->submission, $document);
|
||||
|
||||
return back()->with('success', 'Versi laporan aktif dikemas kini.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user