How can I access the correct URL of my files stored in storage Laravel

0

My drawback is that I can not put the correct url, or if it is correct it does not allow access to the files. I have a function that generates pdf's which with this line I keep those pdf's.

  date_default_timezone_set('America/Bogota');
  $date = Carbon::now();
  $datetime = $date->format('d M Y');
  $name_pdf = Carbon::now()->hour.Carbon::now()->minute.Carbon::now()->second.$request->dirigidoa.".pdf";
  $pdf = \PDF::loadView('pdf.vista',['entidad'=>$request->dirigidoa,
                        'contacto'=>$request->persona,
                        'ciudad'=>$request->ciudad,
                        'referencia'=>$request->referencias,
                        'nombres'=>$nombres,
                        'descripcion'=>$descripcion,
                        'condicion'=>$condicion,
                        'created_at'=>$datetime]);
  Storage::disk('public')->put($name_pdf, $pdf->output()); //esta linea me guarda el pdf creado en storage/public

I recently ran the command: php artisan storage: link to link that folder to / public but I can not establish the correct link in my view.

  @foreach ($list as $lista)
    <tr class="table-active">
      <td>{{$j++}}</td>
      <td>{{$lista->created_at}}</td>
      <td>{{$lista->entidad}}</td>
      <td>{{$lista->contacto}}</td>
      <td>{{$lista->ciudad}}</td>
      <td>{{$lista->referencia}}</td>
      <td><a href="{{url('/storage')}}/{{$lista->url_pdf}}" target="_blank">Link</a> </td>
    </tr>
  @endforeach

I do not know what can be wrong I tested with several link formats /storage/public/archivo.pdf, ../storage/app/public/archivo.pdf and nothing.

    
asked by Eric Js Martinez 13.03.2018 в 14:25
source

1 answer

0

To obtain the url of the file in the Storage, use:

$url = Storage::url('archivo.pdf');

Remember that, if you are using the local driver, the folder must be located in a place that is publicly accessible.

    
answered by 13.03.2018 в 14:43