-1
The idea is to upload confidential documents, so I can’t put them in the folder /public
. The goal is that in the views I can access these private files.
Local:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
Controller Upload:
public function uploadDocumentos(RequestDocumentosDevedors $request, $idDevedor)
{
$data = $request->all();
$random = Str::random(150);
if ($request->hasFile('file') && $request->file('file')->isValid()) {
$name = kebab_case($request->descricao);
$extension = $request->file->extension();
$nameFile = "{$idDevedor}-{$random}.{$extension}";
$data['file'] = $nameFile;
$upload = $request->file->storeAs('documentos/devedor/' . $idDevedor, $nameFile);
$id = $request->devedor_id;
DocumentosDevedors::create($data);
}
return redirect()->route('admin.devedors.documentos', compact('id'));
}
It worked that way:
Route::get(
'teste/{id}/{arquivo}',
function ($id, $arquivo) {
$file = storage_path() . '/app' . '/documentos/devedor/' . $id . '/' . $arquivo;
return response()->download($file);
}
)->middleware('auth');
The ideal is to configure in apache not to have public access in the folders of
/public
.– CypherPotato
In the public/ folder is public access. What I need is to store documents that only the specific user has access to download.
– André Cabral
I don’t know if it would work, but you can try using the storage_path()
storage_path() . 'documentos/devedor/' . $idDevedor
– CypherPotato
Doing a test slightly I think it will work. However as I am in localhost the bars are reversed.
– André Cabral
return E: project Storage/documents/debtor/16/16.pdf
– André Cabral