29 lines
759 B
PHP
29 lines
759 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\ServiceRequest;
|
|
use App\Models\RequestAttachment;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class AttachmentController extends Controller
|
|
{
|
|
public function download(ServiceRequest $request, RequestAttachment $attachment): Response
|
|
{
|
|
abort_unless($attachment->request_id === $request->id, 404);
|
|
|
|
Gate::authorize('view', $request);
|
|
|
|
if (!Storage::disk('local')->exists($attachment->path)) {
|
|
abort(404, 'Файл не найден.');
|
|
}
|
|
|
|
return response()->download(
|
|
Storage::disk('local')->path($attachment->path),
|
|
$attachment->filename
|
|
);
|
|
}
|
|
}
|