23 lines
698 B
PHP
23 lines
698 B
PHP
<?php
|
|
|
|
use App\Models\Preventivo;
|
|
use App\Support\PreventivoPdf;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
Route::get('/', function () {
|
|
return view('welcome');
|
|
});
|
|
|
|
Route::get('/admin/preventivi/{preventivo}/pdf', function (Preventivo $preventivo) {
|
|
if (! $preventivo->pdf_path || ! Storage::disk('local')->exists($preventivo->pdf_path)) {
|
|
$preventivo->pdf_path = PreventivoPdf::genera($preventivo);
|
|
$preventivo->save();
|
|
}
|
|
|
|
return Storage::disk('local')->response(
|
|
$preventivo->pdf_path,
|
|
'preventivo-'.($preventivo->numero ?? $preventivo->id).'.pdf'
|
|
);
|
|
})->middleware(['auth'])->name('preventivi.pdf.show');
|