0

I am running the following loop in my view to display the articles in my database:

@foreach($recentPost as $recent)

    <div class="col-md-6">
        <div class="indi-news-highlight-box">
            <a href="{!!  route('getArticle' , ['id' => $recent->id ]) !!}">
                <img src="{!! public_path().'/images/'.$recent->filePath !!}" alt="{!!  $recent->title  !!}">
            </a>
            <div class="content-box">
                <h3>
                    <a href="{!!  route('getArticle' , ['id' => $recent->id ]) !!}">
                        {{  $recent->title }}
                    </a>
                </h3>
                <p>
                    {!! $recent->blog_content !!}
                </p>
            </div>      
        </div>
    </div>   <!-- End col-md-6 -->

@endForEach

The below line outputs the image in the view:

<img src="{!! public_path().'/images/'.$recent->filePath !!}" alt="{!!  $recent->title  !!}">

Now i don't get an images in my view , and neither are the images broken links , what i see is the below:

enter image description here

Now when i right click , open dev tools and try to open the image in a new tab, i see the following notice:

enter image description here

How do i overcome this permissions error ?? I am using xampp on windows.

EDIT:: What i get with a dummy image placeholder is the below:

enter image description here

Alexander Solonik
  • 9,838
  • 18
  • 76
  • 174

2 Answers2

3

public_path() will return the full path to file, not the url which you want here. Your browser can not open /var/www/app/public/x, it needs the url.

Try with asset() or secure_asset() when working with https

<img src="{!! asset('images/'.$recent->filePath) !!}" alt="{!!  $recent->title  !!}">

For more info on the helpers see: Laravel helper methods

Robert
  • 5,703
  • 2
  • 31
  • 32
0

Somehow for some reason the below does't work:

<img src="{{ public_path().'/images/'.$recent->filePath }}" alt="{!!  $recent->title  !!}">

and the below Does:

<img src="{{ URL::to('/images/'. $recent->filePath) }}" alt="{!!  $recent->title  !!}">

Got the solution from HERE.

Community
  • 1
  • 1
Alexander Solonik
  • 9,838
  • 18
  • 76
  • 174