Certificate manager built on Laravel 13, Livewire 4, and Flux. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
25 lines
857 B
PHP
25 lines
857 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Certificate;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class SharedCertificateController extends Controller
|
|
{
|
|
/**
|
|
* Stream a certificate to an external recipient via a temporary signed
|
|
* URL. The 'signed' middleware is the authorization here, so this runs
|
|
* unauthenticated (the global scope no-ops without a logged-in user).
|
|
*/
|
|
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),
|
|
);
|
|
}
|
|
}
|