Currently I have a project with laravel 5.5 I have some text files stored in storage/public/*
I have been thinking if there is a way to use laravel's blade and open the selected file directly instead of making a request to the backend to retrieve the content then display.
The idea is inside *.blade.php
there will be a button to click, then instead of making request to the backend, can we just open the text file then show the content?
let's say for example, I do have html code like
<input type='hidden' value='filePath' name=path>
<a href="">text file name</a>
when the anchor is clicked, usually it would be making a request to the backend open the file, get the content, pass it back to the front. But what I am thinking is, since the frontend knows where the path is, name of the file. Is it possible to do it at front end? This way no requests need to be done faster too.
But I do not have an idea how to even start it.
Does someone has any suggestions?
Thanks in advance for any help.
Assuming your files are accessible to the person viewing the web page, you can use file URLS (or just type in the URL in the blade file?).
<a href="http://public/fixed/path/to/file">Title</a>
Or, if the files are pre-determined when the blade file is generated then do something like this in your controller:
use Illuminate\Support\Facades\Storage;
public function index()
{
return view('view.name', [
'url' => Storage::url('file.jpg')
]);
}
And in your Blade file:
<a href="{{ $url }}">Title</a>
If you consider the blade file the front-end, then remember it's not hosted on the server once the user is viewing it. You'll need to do something like the above to allow blade to generate the right file URLs (unless you're just talking about static, hosted files)
But, if your reference to back-end and front-end is about where should the logic go, then the answer is "the back end". The point of the MVC pattern is to put the right bits of logic in the right places, so the Blade file (representing V for View in MVC) should only be concerned with presentation, not digging up files and generating URLs.