These are what I have :
Database table named lamanInformasi
, which has these fields: id, judul, isi, created_at, updated_at.
This is what I want :
User can upload document and the files will be stored to database. The file names will be saved to isi
field, and the files itself will be saved to a folder named propic. I've done all of them correctly. Then, I have a problem. When the data from database is showed, there are links in each file name. When user clicks the link, the file will be automatically downloaded. How to make it possible? When I click the link, I have this error: NotFoundHttpException
These are my codes :
index.blade.php -- I put this file inside upload folder
<table class="table table-striped table-bordered" border= "1px solid black">
<thead>
<tr>
<td>ID</td>
<td>Judul</td>
<td>Isi</td>
<td>Created At</td>
<td>Updated At</td>
</tr>
</thead>
<tbody>
@foreach($lamanInformasi as $file)
<tr>
<td>{{$file->id}}</td>
<td>{{$file->judul}}</td>
<td><a href="{{URL::to('upload/' . $file->id)}}">{{$file->isi}}</a></td>
<td>{{$file->created_at}}</td>
<td>{{$file->updated_at}}</td>
</tr>
@endforeach
</tbody>
</table>
LamanInformasiController
public function show($id)
{
$lamanInformasi = $this->model->whereId($id)->firstOrFail();
$downloadFile = response()->download($lamanInformasi->filepath, $lamanInformasi->name);
return view('upload.index', compact('lamanInformasi','downloadFile'));
}
Thanks for your help