I would like to develop a page in which the user can associate (upload) a file (img, pdf, csv ...) to a database record and then having a preview of the file (image or icon) and download it with a click. I think it is a very common scenario but despite of the good laravel documentation and although I found some similar questions (this, this and this) I can't figure it out.
I successfully upload the file (and store the name in the database) with: - the blade view
<form action=""
method="post" enctype="multipart/form-data">
<input type="file" name="order_file"
<input type="submit" title="Upload"> Upload
</form>
-
and the controller
public function uploadfile (Request $request, Order $order) { $this->validate($request, ['order_file' => 'image|mimes:jpeg,bmp,png|max:2000']); $filename = $request->file('order_file')->storeAs('orders',$request->file('order_file')->getClientOriginalName()); $order->order_file = $filename; $order->save(); return redirect()->route('orders.edit',['id'=>$order->id])->with(['flash_message' => 'Order file successfully uploaded (delay).']); }
In the view I add this part to show different URLS
<ul>
<li> Order file : </li>
<li> URL order file : </li>
<li> Asset : </li>
<li> Storage URL : </li>
<li> <img src="????"> </li>
<li> <a href="????">Download</a> </li>
</ul>
The result is
-
Order file : orders/1490379918_crown_gold.png
-
URL order file : http://localhost/mylaravel/public/index.php/orders/1490379918_crown_gold.png
-
Asset : http://localhost/mylaravel/public/storage/orders/1490379918_crown_gold.png
-
Storage URL : /storage/orders/1490379918_crown_gold.png
but I do not understand the right way to complete
via AlexMI