-1

although I am successfully uploaded my image from my laravel projects storage\app\public\images\ directory. Now I want to fetch my images then I don't find any error but my image is not showing besides alt attributes. Here is my code: ProductController.php file:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Product;

class ProductController extends Controller
{
    //
    function index()
    {
        $data=Product::all();
        return view('product',['products'=>$data]);

    }
}

product.blade.php file:

 @foreach($products as $item)
      <div class="item {{$item['id']}}">
          <img src="{{$item['gallery']}}" alt="Chaina"/>
          <div class="carousel-caption">
              <h3>{{$item['name']}}</h3>
              <p>{{$item['description']}}</p>
    </div>
    </div>
       @endforeach
  • possible duplicate [Laravel 5 - How to access image uploaded in storage within View?](https://stackoverflow.com/questions/30191330/laravel-5-how-to-access-image-uploaded-in-storage-within-view) – zahid hasan emon Aug 06 '21 at 09:44

1 Answers1

0

Do you store a path to image in field 'gallery of 'product table? If so. Try this:

    @foreach($products as $item)
    <div class="item {{$item['id']}}">
      <img src="{{Storage::get('public/images/', $item['gallery']) }}" alt="Chaina"/>
            <div class="carousel-caption">
                <h3>{{$item['name']}}</h3>
                <p>{{$item['description']}}</p>
            </div>
    </div>
    @endforeach
  • In my chrome's devtool error is solved using this solution but still i am unable to show my images in my browser after fetching image data from produts table. – Ajeet Ravan Aug 07 '21 at 03:09