Certified/app/Http/Controllers/CertificatePreviewController.php
2026-08-04 10:18:10 +02:00

22 lines
717 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Certificate;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\StreamedResponse;
class CertificatePreviewController extends Controller
{
/**
* Stream a certificate's file inline (for embedding in the view page)
* rather than forcing a download. The global scope on the model ensures
* a foreign certificate resolves to a 404.
*/
public function __invoke(Certificate $certificate): StreamedResponse
{
abort_unless(filled($certificate->file_path) && Storage::disk('local')->exists($certificate->file_path), 404);
return Storage::disk('local')->response($certificate->file_path);
}
}