Certified/app/Http/Controllers/CertificateDownloadController.php
Joël van de Wouw ac340d125c
Some checks failed
linter / quality (push) Failing after 13s
tests / ci (8.3) (push) Failing after 2s
tests / ci (8.4) (push) Failing after 2s
tests / ci (8.5) (push) Failing after 3s
Initial commit
Certificate manager built on Laravel 13, Livewire 4, and Flux.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-12 14:44:58 +02:00

24 lines
775 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Certificate;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\StreamedResponse;
class CertificateDownloadController extends Controller
{
/**
* Stream a certificate the authenticated user owns. 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')->download(
$certificate->file_path,
$certificate->title.'.'.pathinfo($certificate->file_path, PATHINFO_EXTENSION),
);
}
}