Answer the question
In order to leave comments, you need to log in
How to deny access to a folder via url?
I need to deny access to public folder via url, how to do it?
Answer the question
In order to leave comments, you need to log in
Another thing.
To prevent files from being accessible by link, you do not need to place them in a public directory.
I did this:
Register the route
Route::get('p/attach/{id}', [AttachmentController::class, 'show'])
->name('attachment.show')
->middleware(['auth']);
// config/filesystem.php
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'visibility' => 'public',
],
// AttachmentController.php
public function show($id, Request $request, Response $response)
{
// Здесь любая логика проверки прав на просмотр файла.
// ...
/** @var Attachment $attach */
$attach = Attachment::findOrFail($id);
$path = Storage::disk('private')->path($attach->path.$attach->name.'.'.$attach->extension);
return response()->file($path);
}
privateUrl(Attachment $attachment)
{
return route('attachment.show', [
'id' => $attachment->id,
]);
}
@foreach($files as $attachment)
<a class="text-underline"
target="_blank"
href="{{ privateUrl($attachment) }}"
>{{ $attachment->original_name }}</a>
@endforeach
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question