How to us html <img src> to display an image in laravel? - image

I am trying to src an image into my html. Using Laravel as a backend.
<img class="card-img-top" src="storage/app/public/photos/{{$photo}}" alt="Card image cap">
I have also used the system link command and tried,
<img class="card-img-top" src="storage/{{$photo}}" alt="Card image cap">
In the past this would have been sufficent however, when using Laravel this does not link the image.
Does Laravel not allow direct 'src' links, or am I messing up the 'src' file structure?

Laravel uses blade syntax, variables ($) need to be between {{ }} in order to output their value.
So give <img class="card-img-top" src="storage/app/public/photos/{{ $photo }}" alt="Card image cap"> a try :)

i think the simple call like
<img src="storage/image/{{$data->photo}}" alt="">
$data = result from foreach
photo = column in db.

Correct file path is:
src="storage/photos/{{photo}}"
It skips /app/public

src="{{ url('assets/img') }}/{{ $item->photo }}"
Works for me!

Related

Laravel profile photos show only sometimes

I have a profile photo set up in a std header like so
<img src="{{ Auth::user()->profile_photo_url }}" class="img-circle" alt="User Image" />
When I sign in and land on my dashboard page using this header everything works great.
When I route to any other screen using the same header the picture does not show.
If I inspect the img src I get the same img src from all screens wether the picture shows up or not.
Any insight would help.
<img src="storage/profile-photos/1715359786021735.png" class="user-image" alt="User Image">

Avatar Not Showing Laravel

I'm working with laravel framework, I have to create a profile so I changed the table User created in the Auth.. all works perfectly. I also added a Picture for the Profile picture or Avatar in the User table.
I made a profile page Image are showing and even to my nav bar.
this is the code I used.. and it work in other pages.
<img src="img/avatar/{{Auth::user()->picture}}">
this one is for my logo image I put the {{URL::asset}} because it's not showing also in another pages
<img src="{{ URL::asset('img/weblogo.png') }}">
then it works perfectly in all pages
but when I try to use it in the image from my database, It won't work and said
<img src="{{ URL::asset('img/avatar/{{Auth::user()->picture}}') }}">
syntax error, unexpected '}', expecting ')'
in my view
but when I try this, it won't work with all the pages
<img src="img/avatar/{{Auth::user()->picture}}">
Set asset as below
<img src="{{ asset('img/avatar/'.Auth::user()->picture) }}">
Or if you want to use URL::asset then
<img src="{{ URL::asset('img/avatar/'.Auth::user()->picture) }}">
You don't need to use {{ again inside {{ }}
Change
<img src="{{ URL::asset('img/avatar/{{Auth::user()->picture}}') }}">
to
<img src="{{ URL::asset('img/avatar/'.Auth::user()->picture) }}">

In Laravel project images comming in json_decode format like ff1dgadfll but i want to show it in original format in admin stoarge how?

In laravel images comming in json_decode format like jfhfkak56rs but i want to show it in the admin panel in original path when my image name in test.jpg then it should be stored in admin test.jpg not in json_decode when i change the json_decode to json_encode that site showing an error message please help me.
here is my code.
#foreach (json_decode($cs->images, true) as $image)
<li class="wd-casestudy">
<img onClick="changeImage(this)" src="{{ productImage($image) }}" style="width:100%;cursor: pointer" alt="Partner">
</li>
#endforeach

show img with url in laravel 5.4

I have a image that want show in slide show I use html tag <img src="">,
I'm new in laravel and I don't Know How to show image in my blade.
How I can use <img> tag in laravel?
<img src="{{ asset('/public/upload/image.jpg') }}">
If your image in public folder
If you have stored images inside laravel public directory then, you can use asset which refers to public/ directory.
If you have image at public/images/abc.png then, you can add image in view like this:
<img src="{{ asset('images/abc.png') }}">

Symfony2 - Image uploaded only displays when being called in the Twig file

I have an problem with displaying my uploaded image to web/images when using the following line below while inside of the blog text or using a data fixture.
I've tested it by manually calling in the code to display the image inside of the Twig file but I want to use this in a fixture/entering it in the blog text to customize the size/alignment of the images for each post.
Can someone show me what's preventing the image from displaying?
Cheers!
This refuses to display image while in a fixture or inside blog text: (shows an outline of the proper sizing and alignment of image inside the blog text but not the image itself)
<img class="alignleft" src="{{ asset(['images/', news.image]|join) }}" alt="" width="290" height="275" />
Using a web link for an image works fine when in a fixture or when entering a blog text:
<img class="alignleft" src="http://www.example.com/example.jpg" alt="" width="290" height="275" />
Using autoescape false to display the blog text:
{% autoescape false %}
<p>{{ news.blog }}</p>
{% endautoescape %}
You're trying to render a string(variable) as a (sub-)template.
That's why twig isn't processing the {{ asset() }} function.
Auto-escaping is not what you're looking for as it doesn't enable processing of twig functions inside strings.
solution:
the template_from_string function
1.) Enable the Twig_Extension_StringLoader extension that comes bundled with twig in your config.yml
services:
# ...
twig.extension.stringloader:
class: Twig_Extension_StringLoader
tags:
- { name: twig.extension }
Now clear your cache using app/console cache:clear.
2.) If you have your template stored in a variable named news.blog you can now use the function as follows:
{{ include(template_from_string(news.blog)) }}
more information in the documentation: template_from_string

Resources