mad-lawsuit/app/Http/Controllers/DocumentController.php
TheMaddax 06a620406c Phase 1: Email subscription and document download features
- Created SubscriptionController with subscribe/unsubscribe endpoints
- Added subscription API routes (POST /api/subscribe, GET /api/unsubscribe/{token})
- Updated Vue Home component with working subscription form
- Created DocumentController with download endpoint
- Added document download route (GET /api/documents/{id}/download)
- Updated Vue component to link PDF buttons to download route
- Created DocketSeeder with 5 sample docket entries and documents
- Seeded database with test data for development

Features working:
- Email subscription with validation and duplicate checking
- Subscription reactivation for previously unsubscribed emails
- Document download functionality (ready for actual PDFs)
- Sample data for testing UI

Next: Admin dashboard for CRUD operations
2025-12-17 15:51:47 -07:00

34 lines
900 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Document;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\StreamedResponse;
class DocumentController extends Controller
{
/**
* Download a document by ID.
*/
public function download(int $id): StreamedResponse
{
$document = Document::findOrFail($id);
// Check if file exists
if (!Storage::exists($document->file_path)) {
abort(404, 'Document file not found.');
}
// Stream the file to the browser
return Storage::download(
$document->file_path,
$document->original_filename,
[
'Content-Type' => $document->mime_type,
'Content-Disposition' => 'inline; filename="' . $document->original_filename . '"',
]
);
}
}