I was able to successfully save the generated pdf file to the path storage/app/public/pdf. Now I want to open a link to each pdf file from a data table in a view. I keep getting a 404 error whenever I try to open the link from the table in my view. Any help would be greatly appreciated.
Here is the code for the data table in my view(reportLink is just the name of the pdf file):
<h1 style="text-align:center; font-size:50px;">Report History</h1>
<div id="content">
<table id="datatable" class="table table-bordered table-hover table-sm" border="2" style="width:100%;">
<thead>
<tr>
<th style="height:40px;">Date</th>
<th>Report Type</th>
<th>Customer ID</th>
<th>Product ID</th>
<th>Report PDF</th>
</tr>
</thead>
<tbody>
@foreach($report_archives as $report_archive)
<tr>
<td>{{$report_archive->date}}</td>
<td>{{$report_archive->reportType}}</td>
<td>{{$report_archive->customerID}}</td>
<td>{{$report_archive->productID}}</td>
<td><a href="/storage/app/public/pdf/{{$report_archive->reportLink}}">{{$report_archive->reportLink}}</a></td>
</tr>
@endforeach
</tbody>
</table>
</div>
I have tried using url and asset, but I get an error stating "Unclosed '(' does not match '}' "
<td><a href="{{asset('/storage/app/public/pdf/{{$report_archive->reportLink}}')}}">{{$report_archive->reportLink}}</a></td>
<td><a href="{{url('/storage/app/public/pdf/{{$report_archive->reportLink}}')}}">{{$report_archive->reportLink}}</a></td>
It seems like Laravel's symbolic link from storage/app/public to public/storage might not be set up right. You've got your files in storage/app/public, right? Laravel makes those files available at /storage using this symbolic link. You set it up with this command: php artisan storage:link.
You can't just hit /storage/app/public directly from the web because it's not in the web root directory, which is the /public directory. That's where the asset and url helpers come in. They help you generate a URL for an asset depending on whether your request is HTTP or HTTPS.
Now, about that "Unclosed '(' does not match '}' " error, it's because you're trying to nest these curly braces {{ }}. In Laravel's Blade template engine, you use those to print out variables or expressions. So you don't want to nest them like that.
Try this instead:
<td><a href="{{asset('storage/pdf/' . $report_archive->reportLink)}}">{{$report_archive->reportLink}}</a></td>
or
<td><a href="{{url('storage/pdf/' . $report_archive->reportLink)}}">{{$report_archive->reportLink}}</a></td>
That should work, but it's assuming you've got that symbolic link set up right. If not, you can create it with that php artisan storage:link command I mentioned.
Last thing to check: make sure the file path and file actually exist and your web server has the permissions to get at the file. Hope that helps!