Certificate manager built on Laravel 13, Livewire 4, and Flux. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
24 lines
775 B
PHP
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),
|
|
);
|
|
}
|
|
}
|