Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
25 lines
756 B
PHP
25 lines
756 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Document;
|
|
use App\Models\Organization;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class DocumentDownloadController extends Controller
|
|
{
|
|
public function __invoke(Request $request, Organization $organization, Document $document): StreamedResponse
|
|
{
|
|
abort_unless($document->organization_id === $organization->id, 404);
|
|
abort_unless($document->isUpload() && $document->file_path, 404);
|
|
|
|
if ($request->boolean('inline')) {
|
|
return Storage::response($document->file_path, $document->name);
|
|
}
|
|
|
|
return Storage::download($document->file_path, $document->name);
|
|
}
|
|
}
|