Display image in laravel 7 - laravel

I store an image with
$cat->picture = $request->file('catpicture')->store('public/catpictures');
$cat->save();
I do a ls in "/var/www/html/project/storage/app/public/catpictures", the image is saved
I created the symlink
php artisan storage:link
The [/var/www/html/project/public/storage] link has been connected to [/var/www/html/project/storage/app/public].
The links have been created.
In my blade I have:
<img src="{{url($cat->picture)}}" class="img-thumbnail" alt="Responsive image">
which is "public/catpictures/IgTx81OYKVymthuzTydFVepGvFZGALeeW1FmHpas.png"
The image doesnt show,what am I missing?
The src is http://127.0.0.1:8000/public/catpictures/IgTx81OYKVymthuzTydFVepGvFZGALeeW1FmHpas.png

Instead of using url, better to use asset to retrieve asset
Actually you don't need to add public prefix in your store() function. When you call store(), it will use the path from config/filesystems.php. The path will be taken from the default disks.
Asset vs Url
<img src="{{asset('/storage/' . $cat->picture)}}" class="img-thumbnail" alt="Responsive image">

Related

laravel display image from database with blade

i just stored the path of a image that i uploaded into the database, however in the edit section of the form i want to show it and dont seem to find how is the right way to display it i have been trying with:
{{ HTML::image('imgs/picture.jpg') }} -> this one shows the path correctly BUT
using -> {!! Html::image('product_image') !!} doesnt display the path correctly if i use the chrome developer tools inspector i get this:
<img src="http://127.0.0.1:8000/product_image">
what am i doing wrong? what i want is to display the info (the path of the image) that is stored on the database.
thanks!
use Storage::url() ref link https://laravel.com/docs/8.x/filesystem#file-urls
{{ HTML::image(Storage::url('imgs/picture.jpg')) }}
//or
{{ HTML::image(Storage::url($product_image)) }} // here $product_image database path stored by Storage::put() function
it will generate url for laravel storage path like
<img src="http://127.0.0.1:8000/storage/imgs/picture.jpg"> it is correct path

Laravel Vue - How to make vue to look for images in public folder

I am trying to load images from the public folder in the vue components. The asset helper doesn't work in vue , so I need to use the format
<img :src="'img/ic_add-sm.svg'" >
But instead of looking for the images in the public folder , vue is appending the current URL to the image path. For example , if the url is www.example.com/posts
it adds www.example.com/posts/img/ic_add-sm.svg
instead of www.example.com/img/ic_add-sm.svg
Add a forward slash to the beginning of your image path.
<img :src="'/img/ic_add-sm.svg'">
Since you don't appear to be doing anything special you should be able to just use
<img src="/img/ic_add-sm.svg">
At first bind the value of image source
<img :src="getPhoto() + variableName" />
Then create the function under your methods section and simply return the directory location, that's all.
getPhoto(){
return 'images/';
}
Note that, You cant declare directory location directly to :src attribute.

Laravel show s3 image in blade template

I have an image stored in an S3 bucket that is linked to my Laravel app. How can I display this image in a blade template?
So far I have...
<img src= "{{Image::make(Storage::disk('s3')->get('image/' . $filename))}}">
But this is not returning anything.
Does anybody have an example I can see?
The S3 driver has a url function that'll get you a temporary, signed URL to the S3 object, so all you'll need to do is:
<img src="{{ Storage::disk('s3')->url($filename) }}">

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') }}">

How to show image form another folder in laravel 5.2

I want to show picture form another folder. But why it's not working?
<img src="/picture/Capture.JPG" style="width:600px;height:400px">
My folder name is picture and image name is Capture.JPG
To print images ,css and js files correct path laravel have a default function asset()
Try this
<img src="{{ asset('picture/Capture.jpg') }}" style="height:400px;width:400px" >
I find my solution last night.
At first i create a folder in public folder name images. Then i store the picture. And the code formet is here.
<img src="{{url('/images/6.JPG')}}" alt="Image"/>

Resources