Mitch Feaver
Mitch Feaver

Reputation: 37

image working in index.blade.php but not show.blade.php

I am using Laravel to build a Events management system. Users can upload images to be displayed with their event. I have the img tag working on my index.blade.php and assumed I could use the same code on my show.blade.php page, it seems not. I have the image stored in public/images and I am aware I should use storage for this but I am still learning basics so found this easier for now.

<img style="width:100%" src="images/{{$event->image}}">

Upvotes: 2

Views: 533

Answers (4)

Leslie
Leslie

Reputation: 11

when u use js or css or images u should use {{asset('path')}} to get the resource, it has noting to do with the blade u use, but the resources path.

Upvotes: 0

Gufran Hasan
Gufran Hasan

Reputation: 9373

Please use asset() method. The asset() method is used to include CSS/JavaScript/images files, you can use it as:

{{ URL::asset('images/'.$event->image) }}

<img style="width:100%" src="{{ URL::asset('images/'.$event->image) }}">

You can also use this function for CSS and js.

<link href="{{ asset('css/style.css') }}" rel="stylesheet">
<script src="{{ asset('js/custom.js') }}"></script>

For detail please see this article:

https://medium.com/@zwacky/laravels-url-to-vs-url-asset-fd427ed6f7ef

Upvotes: 3

jay dave
jay dave

Reputation: 53

I suggest Not to use URL::asset but only asset method because sometime URL may cause Problem while showing the image...and use dd() function and check whether u are getting the path i.e Public_path , storage_path() or the custom like the image are stored in public directory..

You may use asset() method of Laravel and use any Prefix whatever you like..

Example:

For static

 <img src="{!! asset('assets/images/cams/cam-01.png') !!}" class="img-fluid"
                             alt="Card image cap">

For Dynamic

<img src="{!! $settings->aws_url.$performer->coverimage !!}" class="img-fluid" alt="Card image cap">

Upvotes: 1

Amr Aly
Amr Aly

Reputation: 3905

As @Frank Ayyaz said you can use a backslash to solve this another Laravel-way is using public_path method which returns the fully qualified path to the public directory. so you can do something like:

<img style="width:100%" src="{{ public_path('images/'.$event->image) }}">

Upvotes: 4

Related Questions