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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.