first&last
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user