1 year ago

How can I access images from storage and use it for products

Posted 1 year ago by nic_ttr

Hello! I saved all my product pictures in storage\app\public and I want to access them for every product. I saved them with the id of products (e.g for id_product=1 I have 1.jpg). I was trying to acces them by url (e.g{{$product->id_med}}.jpg) But it doesn't work .

This is the code from routes file

Route::get('storage/{imagini}' , function($imagini)
    $path = storage_path('app/public/' . $imagini);

    if (!File::exists($path)) {

$file = File::get($path);
$type = File::mimeType($path);

$response = Response::make($file, 200);


and the code from my view

 @foreach($products->chunk(3) as $productChunk)

<div class="row">
  @foreach($productChunk as $product)

  <div class="col-xs-6 col-md-4">
    <div class="thumbnail">
      <img src="{{$product->id_med}}.jpg" alt="..." 
      <div class="caption">
        <div class="clearfix">
        <div class="pull-left price ">{{$product->pret}} Ron </div><br>
        <button type="button" class="btn pull-left">Detalio</button> 
        <button type="button" class="btn btn-primary pull-right"> Favorito </button>

Can anyoane help me , please?

Please sign in or create an account to participate in this conversation.